Related
I'm looking for some help as I'm not really sure of the correct terms to use on my query below, so whilst normally I would google this, I'm not really sure what to search for.
I need to work out the total cost for something, where you have a flat rate, and then an additional cost that changes depending on how much of something you have.
So an example, you get expenses paid for millage. If you drive 0-20 miles, you'll get £10. Between 30-50 miles you get 50p per mile. Between 51-100 miles you get £1 per mile and so on, added onto the base rate of the initial £10 you'd get paid as standard.
It's not the best example, but hoping it gives an idea of what I'm after.
If I was doing this by hand I'd know how to work it out, but I'm not to sure what kind of formula I need to be using - I've never had to work with complex formulas past "=sum" until now.
If anyone has any examples they can share or can point me in the right direction of what kind of things to google I'd be most grateful !
Thanks
Well, here is one way, but you don't state what the rate is between 21 and 30...
very basic, but you should be able to edit and expand as you want.
Do note that the limits (30 miles, 50 miles) and rates used in the formula all come from the sheet - so if the 30 mile limit changes to 25 miles - all you need to do is change cell A7...
I apologize for not answering sooner, but I find this question a bit difficult to address due to the complexity of formulas we can encounter. I know the one you documented is not the most complex one we might encounter, but I was not sure if that was your actual problem or if it was intended as a simple example. I have seen a variety of other things which have often thrown me for a loop.
For example, take this set of rules:
Minimum Fee is $23.50 up to $500
$501 - $2,000 = $3.05 per 100 unit increment
$2,001 - $25,000 = $14.00 per 1000 unit increment over $2,000
$25,001 - $50,000 = $10.10 per 1000 unit increment over $25,000
$50,001 - $100,000 = $7.00 per 1000 unit increment over $50,000
$100,001 - $500,000 = $5.60 per 1000 unit increment over $100,000
$500,001 - $1,000,000 = $4.75 per 1000 unit increment over $500,000
$1,000,001 - $9,999,000 = $3.65 per 1000 unit increment over $1,000,000
$10,000,001 and up = $3.65 per 1000 unit increment over $10,000,000
It does not look too different from yours except that there is an increment of something other than a single unit. In other words for the $501 to $2,000 range, $501 to $600 would all get the same additional $3.05 incremental charge. Another dollar would actually double this because it jumps to the next increment. Like your example, each range builds on the prior range. Assuming that these amounts are in colums A through F:
i Low High Fee Base Fee Per
0 1 500 23.50
1 501 2,000 $3.05 100
2 2,001 25,000 $23.50 1000
3 25,001 50,000 $10.10 1000
4 50,001 100,000 $7.00 1000
5 100,001 500,000 $5.60 1000
6 500,001 1,000,000 $4.75 1000
7 1,000,001 9,999,999 $3.65 1000
8 10,000,000 $3.65 1000
Note also that the rate declines as the amounts increase whereas yours appears to increase.
What I did with this is create a maximum value in Column H as follows:
i Max
0 =E3
1 =INT((C4-C3)/F4)*D4
2 =INT((C5-C4)/F5)*D5
3 =INT((C6-C5)/F6)*D6
4 =INT((C7-C6)/F7)*D7
5 =INT((C8-C7)/F8)*D8
6 =INT((C9-C8)/F9)*D9
7 =INT((C10-C9)/F10)*D10
8
The first one, where i is zero, is simply the base fee. The others are computed and copied. There is no maximum for the last row. I did not really think I needed this column but it made it easier to devise the formulas.
Assuming that I put an amount to evaluate in Cell I2, it will be evaluated as follows where the formula in row 3 (where i=0) is the set fee but all others are basically a copied formula:
i 4,950
0 =IF(I$2>=$B3,$H3,0)
1 =IF(I$2>=$B4,IF($H4="",INT((I$2-$C3)/$F4)*$D4,MIN($H4,INT((I$2-$C3)/$F4)*$D4)),0)
2 =IF(I$2>=$B5,IF($H5="",INT((I$2-$C4)/$F5)*$D5,MIN($H5,INT((I$2-$C4)/$F5)*$D5)),0)
3 =IF(I$2>=$B6,IF($H6="",INT((I$2-$C5)/$F6)*$D6,MIN($H6,INT((I$2-$C5)/$F6)*$D6)),0)
4 =IF(I$2>=$B7,IF($H7="",INT((I$2-$C6)/$F7)*$D7,MIN($H7,INT((I$2-$C6)/$F7)*$D7)),0)
5 =IF(I$2>=$B8,IF($H8="",INT((I$2-$C7)/$F8)*$D8,MIN($H8,INT((I$2-$C7)/$F8)*$D8)),0)
6 =IF(I$2>=$B9,IF($H9="",INT((I$2-$C8)/$F9)*$D9,MIN($H9,INT((I$2-$C8)/$F9)*$D9)),0)
7 =IF(I$2>=$B10,IF($H10="",INT((I$2-$C9)/$F10)*$D10,MIN($H10,INT((I$2-$C9)/$F10)*$D10)),0)
8 =IF(I$2>=$B11,IF($H11="",INT((I$2-$C10)/$F11)*$D11,MIN($H11,INT((I$2-$C10)/$F11)*$D11)),0)
The Fee for this is the sum of all of the rows (labeled i, 0 through 8 above). in this example, it would be 23.50 plus 45.75 plus 28.00 for a total of 97.25.
Not too bad. How about a set like this:
No fee if $1,000 or less
$1,001 - $5,000 = $80.00 + 3% of excess over $1,000.00 per 100 unit increment
$5,001 - $10,000 = $250.00 + 2% of excess over $5,000.00 per 500 unit increment
$10,001 - $25,000 = $350.00 + 1% of excess over $10,000.00 per 1000 unit increment
$25,001 and Over = $520.00 + 3/4% of excess over $25,000.00 per 1000 unit increment
In your formula, the initial flat amount never changes and once you've computed the amount for that range, other ranges build upon it. Here, there are steps. For example at $1,000 the fee is zero, but at $1,001, it jumps to $80 as if there were an $80 fee for the first 1000. Without boring you with the entire table, Here is the formula for computing the range from 5,001 to 10,000 assuming that G2 contains the amount to use and Row 5 colums A through E are the following:
Low High Rate Minimum Increment
5,001 10,000 2.00% 250 500
=($D5+$C5*INT(($G$2-($A5-1))/$E5)*$E5)*($G$2>=$A5)*OR($B5="",$G$2<=$B5)
The formula simply looks at the current row and does the computation if the amount in G2 falls within the range from Column A to Column B.
A simplification of all of the above comes when each range cumulatively builds on the prior ranges AND the rate of payment is always increasing, like the U.S. Tax Tables:
Over Not Over
0 9,525 10% of taxable income
9,525 38,700 $952.50 plus 12% of the excess over $9,525
38,700 82,500 $4,453.50 plus 22% of the excess over $38,700
82,500 157,500 $14,089.50 plus 24% of the excess over $82,500
157,500 200,000 $32,089.50 plus 32% of the excess over $157,500
200,000 500,000 $45,689.50 plus 35% of the excess over $200,000
500,000 $150,689.50 plus 37% of the excess over $500,000
Here, we can use something referred to as the "deskpad method" to shortcut the computation
Assuming that the amount to be evaluated is in G1 and these are in column A through C starting in Row 1:
Over Not Over Rate
0 9,525 10.0%
9,525 38,700 12.0%
38,700 82,500 22.0%
82,500 157,500 24.0%
157,500 200,000 32.0%
200,000 500,000 35.0%
500,000 37.0%
We compute the amount based on G1 as follows:
=ROUND(SUMPRODUCT($C$2:$C$8-$C$1:$C$7,$G$1-$A$2:$A$8,N($G$1>$A$2:$A$8)),0)
Note: this is not entered as an array formula.
How does this relate to your question. If the need is as simple as you stated (in other words, the rate is always increasing and we do not have any "steps" in the reimbursement, we can compute it similarly to the U.S. Tax computation.
I created these values in columns A through D starting in row 1:
Over Not Over
0 20 £- Flat Amount of £10.00
20 50 £0.50 £10.00 plus £.50 per mile over 20 miles
50 100 £1.00 £25.00 plus £1.00 per mile over 50 miles
100 £1.50 £75.00 plus £1.50 per mile over 100 miles
where column D is just descriptive. I put the £10.00 flat fee in Cell E1.
Assuming that G1 contains the number of miles, we would compute the reimbursement as:
=$E$1+ROUND(SUMPRODUCT($C$2:$C$5-$C$1:$C$4,$G$1-$A$2:$A$5,N($G$1>$A$2:$A$5)),2))
For example, when G1 is 52 miles, the computation is £27.00
Note: this is not entered as an array formula.
So, if this is the situation, what you would need is a place to house Columns A through C, a place to house the flat amount and a formula similar to what I provided to compute the reimbursement based on the cell housing the number of miles.
Please note that all the earlier items indicate that this formula will not be so simple if the rate is stepped or the rate declines or if the incremental unit is something other than 1 mile.
I hope that some of this makes sense. Good luck.
Things to google : "nested IF in excel"
How to do this in a one-line-formula : enter " =IF(A1<20,10,IF(A1>50,IF(A1>50,10+A1,"u"),0.5*(A1))) " in B1, your milage in A1.
To learn building this :
identify the conditions :
condition1 > 0-20 miles, you'll get £10.
condition2 > between 30-50 miles you get 50p per mile
condition3 > between 51-100 miles you get £1 per mile added onto £10
put the conditions into IF() statement
For contition1 > just type " =if(a1<20,10,0) " at B2 (and try it!) (:
Note : The syntax for IF() function is if("condition","if-true-do-this","if-false-do-this")
Thus, for condition2 > " =if(a1>20,a1*0.5,0) "
And for condition3 > " =if(a1>50,if(a1>50,10+a1),0) " correction : should be " =if(a1>50,10+a1,0) "
Combining all the conditions > "=IF(A1>20,IF(A1>50,IF(A1>50,10+A1,"error"),0.5*(A1)),10) "
Notice that I changed 0 in the "if-false-do-this" part of the equation just to make sure it show something when the milage entered is less than 0.
Hope that helps. /(^_^)
At the moment my formula looks for a LARGE number in column D, which is greater than number in K4, however if the number in K4 is greater than the LARGEST number in col D I get an error #NUM!
=IF(AND($K$4="",$D$5=""),"Not Reported",IF(AND($K$4="",$D$5<>""),"Missing DATA",IF(AND($K$4<>"",$D$5<>""),INDEX($E$5:$E$23,MATCH((SMALL($D$5:$D$23,COUNTIF($D$5:$D$23,""&$K$4)+1)),$D$5:$D$23,0),1))*1-$K$4/SUM(LARGE($D$5:$D$23,COUNTIF($D$5:$D$23,">"&$K$4)+1)+SMALL($D$5:$D$23,COUNTIF($D$5:$D$23,""&$K$4)+1))))+INDEX($E$5:$E$23,MATCH("P98",$A$5:$A$23,0)))))
Can you advise how to alter it, so if the above occurs, instead of taking the number from K4 into consideration, simply replace it with whatever the LARGEST number in col D is and finish the rest of calculations [embedded in the formula]. Appreciate your help.
PS. IFERROR is not an option (it doesn't solve this)
SAMPLE DATA [where the error occurs]:
VALUE OF $K$4
250000
COLUMN A
PERCENTILE
P10
P20
P30
P40
P50
P60
P70
P80
P90
P91
P92
P93
P94
P95
P96
P97
P98
P99
P100
COLUMN D
NUMBER
3500
4096.79
10000
13500
15000
18299.46
25000
39000
50000
50000
50000
50000
200000
200000
200000
200000
200000
200000
200000
COLUMN E
VOLUME
2
2
1
2
1
2
2
1
2
0
0
0
1
0
0
0
0
0
0
I can't give an exact answer since I don't have exact detail about what you're trying to do, however it sounds like you want to do something like this:
=max(k4, d:d)
So: If K4 is the same are bigger than the largest number in Column D, then use K4. Otherwise, use the biggest number in Column D.
More Information:
Office.com : MAX Function
MAX vs MAXA vs LARGE and MIN vs MINA vs SMALL Functions in Excel
So, this works for me:
=IF($J$4="",F27,(IF(J4>=MAX(B5:B23),(INDEX($C$5:$C$23,MATCH((SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&IF(J4>MAX(B5:B23),MAX(B5:B23),J4))+1)),$B$5:$B$23,0),1))*(1-((IF(J4>MAX(B5:B23),MAX(B5:B23),J4))/SUM(LARGE($B$5:$B$23,COUNTIF($B$5:$B$23,">"&(IF(J4>MAX(B5:B23),MAX(B5:B23),J4)))+1)+SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&(IF(J4>MAX(B5:B23),MAX(B5:B23),J4)))+1))))+INDEX($C$5:$C$23,MATCH("P98",$A$5:$A$23,0),1),IF(J4<=MIN(B5:B23),INDEX($C$5:$C$23,MATCH((SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,">"&IF(J4<MIN(B5:B23),MIN(B5:B23),J4))+1)),$B$5:$B$23,0),1))*(1-((IF(J4<MIN(B5:B23),MIN(B5:B23),J4))/SUM(LARGE($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&(IF(J4<MIN(B5:B23),MIN(B5:B23),J4)))+1)+SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,">"&(IF(J4<MIN(B5:B23),MIN(B5:B23),J4)))+1))))+INDEX($C$5:$C$23,MATCH("P98",$A$5:$A$23,0),1),(INDEX($C$5:$C$23,MATCH((SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&$J$4)+1)),$B$5:$B$23,0),1))*(1-($J$4/SUM(LARGE($B$5:$B$23,COUNTIF($B$5:$B$23,">"&$J$4)+1)+SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&$J$4)+1))))+INDEX($C$5:$C$23,MATCH("P98",$A$5:$A$23,0),1)))))
I had to also hedge against the K4 (or J4) value being <MIN(B5:B23)
I have a table with provision levels.
Sales Provision
0 5%
20 000 22%
100 000 30%
A salesman has 5% provision on the first 20 000, 22% on the next 80 000 and 30% on everything above that.
For example a salesman who sells for 230 000 will have provision
=20 000 * 0,05 + 80 000 * 0,22 + 130 000 * 0,30
How can I express this efficiently with a formula? The formula
Needs to be easy to copy to several rows (where a salesman is described by each row)
Needs to work even if I add more provision levels
Well I can say this works (hopefully) for requirement #2:
Needs to work even if I add more provision levels
But note that I am unsure about requirement #1:
Needs to be easy to copy to several rows (where a salesman is described by each row)
Anyway, with this data:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 57600
100000 0.3
I used this formula in E2:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))+(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1)),E1*B1)
If we break this formula down:
The first basic step is to find the index at which the sale value resides. This is the first lower value compared to the sale value. In your example data this is straight forward because the index is the last in the provision list. However to accommodate sale values that fall within the list range we can use:
MATCH(E1,A:A,1)
where E1 is the sale value and A:A is the sale-provision list.
Using this we can incorporate an INDIRECT to get the desired range we need to work with. In this case A1 to A & Index:
INDIRECT("A1:A"&MATCH(E1,A:A,1))
But even within this range we need to figure out two distinct values:
The provision value index lower than our sale value (i.e. 20 000 * 0.05 + 80 000 * 0.22)
The rest of the provision sale value (i.e. 130 000 * 0.30)
So to get the first value we need to set up an array like this:
(20000 - 0) * 0.05 = 20000*.05 = 1000
(100000 - 20000) * 0.22 = 80000*.22 = 17600
SUM = 18600
That can be done by using
(A2:A3 - A1:A2)*(B1:B2)
But to put that in our INDIRECT formula, that would look like
INDIRECT("A2:A"&MATCH(E1,A:A,1)) <- A2:A3
INDIRECT("A1:A"&MATCH(E1,A:A,1)-1) <- A1:A2
INDIRECT("B1:B"&MATCH(E1,A:A,1)-1) <- B1:B2
(INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Just surround that with a SUMPRODUCT to get the total:
SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Then the second value is just the total sale value subtracted by our index value and multiplied by the corresponding provision rate. So that would be:
(E1-A3)*B3
We actually don't need INDIRECT here, a couple INDEX - MATCH lookups will do:
E1 <- E1
INDEX(A:A,MATCH(E1,A:A,1)) <- A3
INDEX(B:B,MATCH(E1,A:A,1)) <- B3
(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1))
Then adding those to formulas together results in the derived formula I showed earlier.
The final addition however was to add an IFERROR wrapper because if the value is less than the first non-zero provision the INDEX-MATCH and INDIRECT will fail. So in the case of an error that means we just need to multiply the sale value by the first provision rate:
E1*B1
And of course if you add an additional provision row:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 63600
100000 0.30
200000 0.50
Or change the provision:
A B C D E
------------------------------------------
0 0.05 Value 22000
20000 0.22 Total Provision 1440
100000 0.30
The formula will index to the proper provision and calculate it properly.
Also,
Since I know I use commas and decimals in my locale and I realized you don't here is the formula for semi-colon list separator:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1;A:A;1))-INDIRECT("A1:A"&MATCH(E1;A:A;1)-1))*INDIRECT("B1:B"&MATCH(E1;A:A;1)-1))+(E1-INDEX(A:A;MATCH(E1;A:A;1)))*INDEX(B:B;MATCH(E1;A:A;1));E1*B1)
I am building an envelope system where I withdraw a number of bills each pay period and put them into envelopes. What I am trying to do is to determine via formula how many bills of each I need to have. Here is an example:-
My funds would be:
Kids $ 10
Car $ 50
Gas $100
Groceries $225
Gifts $ 40
---------------
Total: $425
What I want is a base formula to extract the number of bills of each of: $1, $5, $10, $20 and $50
How to extract numbers of $50s from this list which should give me 7 [1 Car, 2 Gas, 4 Groceries]?
Ultimate goal should be this:
0 $ 1 bills $ 0
1 $ 5 bills $ 5
1 $10 bills $ 10
3 $20 bills $ 60
7 $50 bills $350
--------------------
Total Cash: $425
UNTESTED. With Kids in A2 and 50,20,10,5,1 in C1:G1 then perhaps in C2 and copied across and down:
=INT(MIN($B2,$B2-SUMPRODUCT($B$1:B$1*$B2:B2))/C$1)
The results might then be summed by column (excluding the labels) to get the count by denomination and each sum multiplied by the column labels (eg =SUM(C2:C10)*C$1) then the sums summed as a cross-check on the total.
Assuming your table is in range A2:B6, I would use some auxiliary cells on its right, like this:
| A | B | C | D | E | F | G |
50 20 10 5 1
Kids 10 0 0 1 0 0
Car 50 1 0 0 0 0
Gas 100 2 0 0 0 0
Groceries 225 4 1 0 1 0
Gifts 40 0 2 0 0 0
These are the formulas in row 2:
C2: =ROUNDDOWN(B2/C$1,0)
D2: =ROUNDDOWN((B2-C2*C$1)/D$1,0)
E2: =ROUNDDOWN((B2-C2*C$1-D2*D$1)/E$1,0)
F2: =ROUNDDOWN((B2-C2*C$1-D2*D$1-E2*E$1)/F$1,0)
G2: =ROUNDDOWN((B2-C2*C$1-D2*D$1-E2*E$1-F2*F$1)/G$1,0)
These formulas could be a bit simpler if you use more auxiliary columns with intermediate results.
Then just copy them to the rows below. Finally, you get the results using a simple SUM per auxiliary bill column, placing them as you like and multiplying those results by the bill value in another column.
One possible way to do this would be to implement the following algorithm:
As in your example we have (a,b,c,d,e,f)=(10,50,100,225,40) as our set of values. For each value run =ROUNDDOWN(a/50,0),=ROUNDDOWN(b/50,0), and so on in a column adjacent to your column of values.
Next, multiply these values by the divisor (in this case 50) and subtract this from the initial amount.
Now run this again in a loop for 10, 5, and 1. That is, run this over the array of divisors (50,10,5,1). You will need three columns for each divisor value, one for the initial use of =ROUNDDOWN(), one for the multiplication, and one for the subtraction. In total then you'll need 12 columns of information.
There is probably a way to implement this in VBA that will cut it down to the three columns of counts you need for each bill type with ease.
I've got 3 cells in my spreadsheet that have the layout as below. These values are dynamic, however what I need to do is split a percentage over the 3 fields, and then increase the number.
Total Staff Costs £1,000.00
Total Hardware Costs £0.00
Total Expenses £400.00
For instance, the above comes to a total of £1400, however I need to charge 10% of my own time on top of this so £140.
What I can't just do though, is take this 10% and split it over the 3 fields, ie. I can't just add £46.70 to each field, because no hardware has been bought, so to say its £46.70 would raise some questions. I need to split it proportionally between each one.
How can I go about adding X% to the fields proportionally?
Wouldnt the logic be to determine the percentage of the total for each field. Then multiply that percentage by the total of the 10%
so you have 3 fields totalling 1400
so 1000 / 1400 = .714286
so 0 / 1400 = 0
so 400/ 1400 = .0285714
now multiply these by the totals
so 1400 * .714286
so 1400 * 0
so 1400 * .0285714
These should total to the 10%
so all your data is in Column b in cells 1, 2, 3
The formula that would go in to the cells C1, C2, C3 (assuming you want these totals in the next column over)
=(B1/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C1
=(B2/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C2
=(B3/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C3