Need an IF THEN nested formula to solve this problem

bobuk1973

New Member
Joined
Apr 17, 2016
Messages
4
I have three columns that give in order the number of small items (column A), the number of medium items (column B) and the number of large items (column C).
Each of the quantities can be anything from 0 to 999.
There is a charge made for the total number of items. The charge is calculated on a price for the first one and then a set rate for each of the subsequent of that type.
Only the first of the largest items is charged at the first item rate, then the rest of those type and each of any of a smaller type are charged at the subsequent rate.
So if there are 3 large 3 medium and 3 small the first of the large is charged at the first rate for large, then the other 2 large are charged at the subsequent rate and the 3 medium and 3 small are charged all at the subsequent rate for that type.
If there are no large, 3 medium and 3 small then the first medium item is charged at the first rate for medium, the other two medium charged at the subsequent medium rate and the three small charged each at the subsequent small rate.
The charges for first and subsequent for each category are else where in the spreadsheet say for the purpose of the example
M1 First Small charge (per unit) N1 small subsequent charge (per unit)
M2 First Medium charge (per unit) N2 medium subsequent charge (per unit)
M3 First large charge (per unit) N3 large subsequent charge (per unit)
I would like help with a code to work out the total charge.
Hope you can help
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
See if this is what you want...
[Table="width:, class:grid"][tr][td] [/td][td]
A​
[/td][td]
B​
[/td][td]
C​
[/td][td]
D​
[/td][td]
E​
[/td][td]
F​
[/td][td]
G​
[/td][td]
H​
[/td][td]
I​
[/td][td]
J​
[/td][td]
K​
[/td][td]
L​
[/td][td]
M​
[/td][td]
N​
[/td][/tr]
[tr][td]
1​
[/td][td]Small[/td][td]Med[/td][td]Large[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]small[/td][td]
5​
[/td][td]
1​
[/td][/tr]

[tr][td]
2​
[/td][td][/td][td][/td][td][/td][td]Small[/td][td]Med[/td][td]Large[/td][td]Total[/td][td][/td][td][/td][td][/td][td][/td][td]med[/td][td]
50​
[/td][td]
10​
[/td][/tr]

[tr][td]
3​
[/td][td]
3​
[/td][td]
3​
[/td][td]
3​
[/td][td]
3​
[/td][td]
30​
[/td][td]
700​
[/td][td]
733​
[/td][td][/td][td][/td][td][/td][td][/td][td]large[/td][td]
500​
[/td][td]
100​
[/td][/tr]

[tr][td]
4​
[/td][td]
3​
[/td][td]
3​
[/td][td][/td][td]
3​
[/td][td]
70​
[/td][td]
0​
[/td][td]
73​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
5​
[/td][td]
3​
[/td][td][/td][td][/td][td]
7​
[/td][td]
0​
[/td][td]
0​
[/td][td]
7​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
6​
[/td][td]
4​
[/td][td]
4​
[/td][td]
4​
[/td][td]
4​
[/td][td]
40​
[/td][td]
800​
[/td][td]
844​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
7​
[/td][td]
4​
[/td][td]
4​
[/td][td][/td][td]
4​
[/td][td]
80​
[/td][td]
0​
[/td][td]
84​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
8​
[/td][td]
4​
[/td][td][/td][td][/td][td]
8​
[/td][td]
0​
[/td][td]
0​
[/td][td]
8​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
9​
[/td][td]
1​
[/td][td]
10​
[/td][td]
100​
[/td][td]
1​
[/td][td]
100​
[/td][td]
10400​
[/td][td]
10501​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
10​
[/td][td]
2​
[/td][td]
20​
[/td][td]
200​
[/td][td]
2​
[/td][td]
200​
[/td][td]
20400​
[/td][td]
20602​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
11​
[/td][td]
3​
[/td][td]
30​
[/td][td]
300​
[/td][td]
3​
[/td][td]
300​
[/td][td]
30400​
[/td][td]
30703​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
12​
[/td][td]
4​
[/td][td]
40​
[/td][td]
400​
[/td][td]
4​
[/td][td]
400​
[/td][td]
40400​
[/td][td]
40804​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
13​
[/td][td]
5​
[/td][td]
50​
[/td][td]
500​
[/td][td]
5​
[/td][td]
500​
[/td][td]
50400​
[/td][td]
50905​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]


Your data would be in A:C.

I added D:F to show what the individual calcs would be so you can ceck, but you don't need them.

Then your total is in G....
G3=IF(C3>0,((C3-1)*$N$3)+$M$3,0)
+IF(B3>0,((B3-1)*$N$2)+IF(C3>0,$N$2,$M$2),0)
+IF(A3>0,((A3-1)*$N$1)+IF(B3>0,$N$1,$M$1),0)

Each like on that formula calcs 1 of the columns
 
Upvote 0
See if this is what you want...
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A​
[/TD]
[TD]
B​
[/TD]
[TD]
C​
[/TD]
[TD]
D​
[/TD]
[TD]
E​
[/TD]
[TD]
F​
[/TD]
[TD]
G​
[/TD]
[TD]
H​
[/TD]
[TD]
I​
[/TD]
[TD]
J​
[/TD]
[TD]
K​
[/TD]
[TD]
L​
[/TD]
[TD]
M​
[/TD]
[TD]
N​
[/TD]
[/TR]
[TR]
[TD]
1​
[/TD]
[TD]Small[/TD]
[TD]Med[/TD]
[TD]Large[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]small[/TD]
[TD]
5​
[/TD]
[TD]
1​
[/TD]
[/TR]
[TR]
[TD]
2​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Small[/TD]
[TD]Med[/TD]
[TD]Large[/TD]
[TD]Total[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]med[/TD]
[TD]
50​
[/TD]
[TD]
10​
[/TD]
[/TR]
[TR]
[TD]
3​
[/TD]
[TD]
3​
[/TD]
[TD]
3​
[/TD]
[TD]
3​
[/TD]
[TD]
3​
[/TD]
[TD]
30​
[/TD]
[TD]
700​
[/TD]
[TD]
733​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]large[/TD]
[TD]
500​
[/TD]
[TD]
100​
[/TD]
[/TR]
[TR]
[TD]
4​
[/TD]
[TD]
3​
[/TD]
[TD]
3​
[/TD]
[TD][/TD]
[TD]
3​
[/TD]
[TD]
70​
[/TD]
[TD]
0​
[/TD]
[TD]
73​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
5​
[/TD]
[TD]
3​
[/TD]
[TD][/TD]
[TD][/TD]
[TD]
7​
[/TD]
[TD]
0​
[/TD]
[TD]
0​
[/TD]
[TD]
7​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
6​
[/TD]
[TD]
4​
[/TD]
[TD]
4​
[/TD]
[TD]
4​
[/TD]
[TD]
4​
[/TD]
[TD]
40​
[/TD]
[TD]
800​
[/TD]
[TD]
844​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
7​
[/TD]
[TD]
4​
[/TD]
[TD]
4​
[/TD]
[TD][/TD]
[TD]
4​
[/TD]
[TD]
80​
[/TD]
[TD]
0​
[/TD]
[TD]
84​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
8​
[/TD]
[TD]
4​
[/TD]
[TD][/TD]
[TD][/TD]
[TD]
8​
[/TD]
[TD]
0​
[/TD]
[TD]
0​
[/TD]
[TD]
8​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
9​
[/TD]
[TD]
1​
[/TD]
[TD]
10​
[/TD]
[TD]
100​
[/TD]
[TD]
1​
[/TD]
[TD]
100​
[/TD]
[TD]
10400​
[/TD]
[TD]
10501​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
10​
[/TD]
[TD]
2​
[/TD]
[TD]
20​
[/TD]
[TD]
200​
[/TD]
[TD]
2​
[/TD]
[TD]
200​
[/TD]
[TD]
20400​
[/TD]
[TD]
20602​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
11​
[/TD]
[TD]
3​
[/TD]
[TD]
30​
[/TD]
[TD]
300​
[/TD]
[TD]
3​
[/TD]
[TD]
300​
[/TD]
[TD]
30400​
[/TD]
[TD]
30703​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
12​
[/TD]
[TD]
4​
[/TD]
[TD]
40​
[/TD]
[TD]
400​
[/TD]
[TD]
4​
[/TD]
[TD]
400​
[/TD]
[TD]
40400​
[/TD]
[TD]
40804​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
13​
[/TD]
[TD]
5​
[/TD]
[TD]
50​
[/TD]
[TD]
500​
[/TD]
[TD]
5​
[/TD]
[TD]
500​
[/TD]
[TD]
50400​
[/TD]
[TD]
50905​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Your data would be in A:C.

I added D:F to show what the individual calcs would be so you can ceck, but you don't need them.

Then your total is in G....
G3=IF(C3>0,((C3-1)*$N$3)+$M$3,0)
+IF(B3>0,((B3-1)*$N$2)+IF(C3>0,$N$2,$M$2),0)
+IF(A3>0,((A3-1)*$N$1)+IF(B3>0,$N$1,$M$1),0)

Each like on that formula calcs 1 of the columns

That works perfectly.. Thanks very much for your help and quick response.
 
Upvote 0
There appears to be one problem with the formula when there is one large and one small the value out putted is for first large and first small not first large and subsequent small?

ive tried to add an extra check in the last part of the formula to fix it but don't have the knowledge.
 
Upvote 0
OK I guessed if there was a large, the others would have values too.

Try this instead....
=IF(C3>0,((C3-1)*$N$3)+$M$3,0)
+IF(B3>0,((B3-1)*$N$2)+IF(C3>0,$N$2,$M$2),0)
+IF(A3>0,((A3-1)*$N$1)+IF(OR(B3>0,C3>0),$N$1,$M$1),0)
 
Upvote 0
OK I guessed if there was a large, the others would have values too.

Try this instead....
=IF(C3>0,((C3-1)*$N$3)+$M$3,0)
+IF(B3>0,((B3-1)*$N$2)+IF(C3>0,$N$2,$M$2),0)
+IF(A3>0,((A3-1)*$N$1)+IF(OR(B3>0,C3>0),$N$1,$M$1),0)


Thanks very much will try that out and can see where the extra check is in at the end of the formula.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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