Nested Formula - Calculate cumulative charge based on value in reference cells

DavePhil2

New Member
Joined
Oct 21, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi

I'm hoping someone can help me with the following nested formula issue.

What I would like to do is calculate a cumulative demurrage charge based on the values in two reference cells.
Formula to go into cell H34.
Reference cells are H7 (20FT/40FT) & H27 (calculated field - number of days).

If H7=20FT & H27=30, then the formula should work as follows
5 days @ €35 (D29) = €175, plus,
8 days @ €55 (D30) = €440, plus,
14 + days @ €66 (D31) = €1122.
SUMPRODUCT = €175 + €440 + €1122 = €1737

If H7=40FT & H27=30, then the formula should work as follows
5 days @ €60 (F29) = €300, plus,
8 days @ €100 (F30) = €800, plus,
14 + days @ €115 (F31) = €1955.
SUMPRODUCT = €300 + €800 + €1955 = €3055

Similarly, if the value in H27 fell between one on the early date ranges, the formula would only calculate those days.

Example 1

If H7=20FT & H27=10, then the formula should work as follows
5 days @ €35 (D29) = €175, plus,
5 days @ €55 (D30) = €275, plus,
SUMPRODUCT = €175 + €275 = €450

If H7=40FT & H27=10, then the formula should work as follows
5 days @ €60 (F29) = €300, plus,
5 days @ €100 (F30) = €500, plus,
SUMPRODUCT = €300 + €500 = €800

Example 2

If H7=20FT & H27=4, then the formula should work as follows
4 days @ €35 (D29) = €140,
SUMPRODUCT = €140

If H7=40FT & H27=4, then the formula should work as follows
4 days @ €60 (F29) = €240, plus,
SUMPRODUCT = €240

I hope the above makes sense.

thanks for your help in advance

1666356042309.png
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I calculated the charge in a formula.
The example in C3 names the Brackets and the Rate Differentials.
Name the information in Name Manager by looking at the information or reviewing the formula in B3.

Brackets aB ={0;5;13}
Rates r_20 ={35;20;11}
N.B. To post an extract of your sheet, you can use the forum's tool that is named XL2BB.

Commission2022.xlsm
ABCDEF
1Days50
2Category20
3Amount3,057.003,057.00
4
5
6BracketsRates 20 --- Arithmetic ---Rates 40
7cell b7 is blankBy BracketCumulative
8035175.00175.0060
9555440.00615.00100
1013662,442.003,057.00115
111E+308
9a
Cell Formulas
RangeFormula
B3B3=SUMPRODUCT(--(B1>{0;5;13}),B1-A8:A10,B8:B10-B7:B9)
C3C3=SUMPRODUCT(--(B1>aB),(B1-aB),CHOOSE(MATCH(B2,{20,40},0),r_20,r_40))
C8:C10C8=MAX(0,MIN($B$1,A9)-A8)*B8
D8D8=MAX(0,MIN($B$1,A9)-A8)*B8+N(D7)
D9:D10D9=MAX(0,MIN($B$1,A10)-A9)*B9+D8
 
Last edited:
Upvote 0
Please provide more information on the number of days calculations.



Commission2022.xlsm
ABCD
1Days10
2Category40
3Amount800.00
4
9a
Cell Formulas
RangeFormula
C3C3=SUMPRODUCT(--(B1>aB),(B1-aB),CHOOSE(MATCH(B2,{20,40},0),r_20,r_40))
 
Last edited:
Upvote 0
Book1
BCDEFGH
740FT
8
9
10
11
12
13
14
15
16
17MinMax20FT40FT
18153560
1961355100
201466115
21
22
23
24
25
26
27Days4
28
29
30
31
32
33
34Cost240
Sheet1
Cell Formulas
RangeFormula
H34H34=IFS(H7="20FT",IF(H27<=5,H27*D18,5*D18+IF(H27-C18<=8,(H27-C18)*D19,8*D19)+IF(H27>=14,(H27-13)*D20,0)),H7="40FT",IF(H27<=5,H27*E18,5*E18+IF(H27-C18<=8,(H27-C18)*E19,8*E19)+IF(H27>=14,(H27-13)*E20,0)))
Cells with Data Validation
CellAllowCriteria
H7List=$D$17:$E$17
 
Upvote 0
Sorry for the delay in replying.
thanks for all the responses.
@Kerryx, the above worked perfectly. Thank you.
 
Upvote 0
I have another variation of the above that I need some help with, please.

The same type of nested formula, just with a couple of extra variables.
Formula to go into cell H16.
Reference cells are H4 ("Dublin" or "Cork") & H7 ("20FT" or "40FT")
H14 (calculated field - number of days).

IF(AND(H4="Dublin",H7="20FT") then the formula should work as follows:
A. 0 - 6 days @ €30 (S3) plus,
B. 7 - 18 days @ €40 (S4) plus,
C. 19 - 46 days @ €80 (S5) plus,
D. 47 + days @ €120 (S6).
SUMPRODUCT = A + B + C + D

See the table in Q1 - T6.

IF(AND(H4="Dublin",H7="40FT") then the formula should work as follows:
A. 0 - 6 days @ €50 (T3) plus,
B. 7 - 18 days @ €70 (T4) plus,
C. 19 - 46 days @ €150 (T5) plus,
D. 47 + days @ €220 (T6).
SUMPRODUCT = A + B + C + D

See the table in V1 - Y6.

Example 1

H4="Dublin" AND H7="20FT"
H14 = 34 days

the formula should work as follows
6 days @ €30 (S3) = €180, plus,
12 days @ €40 (S4) = €480, plus,
16 days @ €80 (S5) = €1280
SUMPRODUCT = €180 + €480 + €1280 = €1940

H4="Dublin" AND H7="40FT"
H14 = 50 days

6 days @ €50 (T3) = €300, plus,
12 days @ €70 (T4) = €840, plus,
28 days @ €150 (T5) = €4200, plus,
4 days @ €220 (T6) = €880
SUMPRODUCT = €300 + €840 + €4200 + €880 = €6220

I hope the above makes sense.

thanks for your help in advance


1666973027452.png
 
Upvote 0
cork..Dublin.xlsx
ABCDEFGHIJKL
1
2
3
4DublinCork
5Dublin
6
740FT
8
9
10
11
12
13
14
15
16
17LocMinMax20FT40FT
18Cork153560
19Cork61355100
20Cork1466115
21Dublin163050
22Dublin7184070
23Dublin194680150
24Dublin47120220
25
26
27Days50
28
29
30
31
32
33
34Cost6220
Sheet1
Cell Formulas
RangeFormula
H34H34=IFS(AND(H4="Cork",H7="20FT"),IF(H27<=5,H27*D18,5*D18+IF(H27-C18<=8,(H27-C18)*D19,8*D19)+IF(H27>=14,(H27-13)*D20,0)), AND(H4="Cork",H7="40FT"),IF(H27<=5,H27*E18,5*E18+IF(H27-C18<=8,(H27-C18)*E19,8*E19)+IF(H27>=14,(H27-13)*E20,0)),AND(H4="Dublin",H7="20FT"),IF(H27<=6,H27*D21,6*D21+IF(AND(H27-C21>=1,H27-C21<=12),(H27-C21)*D22,IF(H27>=18,12*D22,0))+IF(AND(H27-C22>=1,H27-C22<=28),(H27-C22)*D23,IF(H27>=46,28*D23,0)) +IF(H27>=47,(H27-C23)*D24,0)), AND(H4="Dublin",H7="40FT"),IF(H27<=6,H27*E21,6*E21+IF(AND(H27-C21>=1,H27-C21<=12),(H27-C21)*E22, IF(H27>=18,12*E22,0))+IF(AND(H27-C22>=1,H27-C22<=28),(H27-C22)*E23,IF(H27>=46,28*E23,0)) +IF(H27>=47,(H27-C23)*E24,0)))
Cells with Data Validation
CellAllowCriteria
H4List=$K$4:$K$5
H7List=$D$17:$E$17
 
Upvote 0
see posts 2 and 3
This post considers your new tiers and rates

Commission2022.xlsm
GH
1
2
3
4Dublin
5
6
740FT
8
9
10
11
12
13
1450
15
16
176,220.00
18
9a
Cell Formulas
RangeFormula
H17H17=IF(H4="Dublin",SUMPRODUCT(--(H14>aB),(H14-aB),CHOOSE(MATCH(H7,{"20FT","40FT"},0),r_20,r_40)),IF(H4="York","Formula",""))
 
Upvote 0
Commission2022.xlsm
H
4Dublin
5
6
740FT
8
9
10
11
12
13
1450
15
16
176,220.00
18
9a
Cell Formulas
RangeFormula
H17H17=IF(H4="Dublin",SUMPRODUCT(--(H14>d_B),(H14-d_B),CHOOSE(MATCH(H7,aL,0),d_R20,d_R40)),IF(H4="Cork",SUMPRODUCT(--(H14>c_B),(H14-c_B),CHOOSE(MATCH(H7,aL,0),c_R20,c_R40)),""))
 
Upvote 0
thank you so much, everyone.
this seems to be working correctly and has saved me a lot of time.
Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top