Doing an operation before SUMIF or MATCH-ing multiple values to multiply before summing - excel

I have an Excel document with multiple small tables in it. Here, each table describes a single project, and at the end of the worksheet, I want to create a summary that doesn't have "hardcoded" locations so that that when the amount of projects (tables) is adjusted, it doesn't break all the formulas. Basically, it looks like this:
A B
1 Project 1
2 Units 200
3 Price / Unit 10
4 Material / Unit 5
5 Handling / Unit 1
6 Total cost 6
7 Profit Margin / Unit 4
8
9 Project 2
10 Units 100
11 Price / Unit 5
12 Material / Unit 1
13 Handling / Unit 1
14 Total cost 2
15 Profit Margin / Unit 3
16
...
19 Summary
20 Units =SUMIF( A$1:A19 ; A20 ; B$1:B19 )
21 Material costs ???
22 Handling costs ???
23 Total Profit ???
Here, there may be an arbitrary amount of projects and I'm unsure how to create a formula that directly calculates the total material costs (and by the same pattern, Handling and Total Profit). For the total units, I can simply use a =SUMIF( A$1:A19 ; A20 ; B$1:B19 ) instead of =B2 + B2 by having the function search col A for the keyword "Units" but in order to do this for the total material costs, I need to multiply first. Eg, it would be =B2*B4 + B10*B12.
My first idea was to use an INDEX MATCH approach to extract a subarray from each table and then sum it all up using SUMPRODUCT however the MATCH function unfortunately only returns the first result and I can't get it to output an array of results (I think this is just a limitation with the function?).
I guess it would also be possible to simply add extra lines to each table to pre-calculate these products, but I don't like that solution as it would give the tables a lot of unnecessary extra bloat and I'd really like to solve this in one formula.
Any help would be greatly appreciated!

I came up with a dirty solution, using SUMPRODUCT formula that works if your using Office 365 :
example calculating total handling cost:
=SUMPRODUCT(FILTER(B:B,A:A="Units"),FILTER(B:B,A:A="Handling / Unit"))
FILTER(B:B,A:A="Units"), returns an array of values on the right of cells containing "Unit"
FILTER(B:B,A:A="Handling / Unit"), returns an array of values on the right of cells containing "Handling / Unit"

Related

Simple(r) Excel formula to calculate forward stock (inventory) cover

This is a perennial question for retailers, for which there are a number of solutions in existence:
How can you calculate the "forward cover" of a product knowing its current inventory and armed with forward sales estimates.
eg.
current inventory 100 units (cell A1)
weekly forward sales estimates: 25, 30, 10, 40, 90... (in range
A2:AX)
Here the answer would be 3.875 weeks (3 full weeks plus 0.875 of week 4)
I have a UDF to do this already.
I also have some slightly complicated array functions to do this, eg.
=MATCH(TRUE,SUBTOTAL(9,OFFSET(A2:A13,,,ROW(A2:A13)-ROW(A2)+1))>A1,0)-1+(A1-SUM(A2:INDEX(A2:A13,MATCH(TRUE,SUBTOTAL(9,OFFSET(A2:A13,,,ROW(A2:A13)-ROW(A2)+1))>A1,0)-1)))/INDEX(A2:A13,MATCH(TRUE,SUBTOTAL(9,OFFSET(A2:A13,,,ROW(A2:A13)-ROW(A2)+1))>A1,0)-1+1)
I was wondering if there is a neater way with these 'new-fangled' array functions which have been available for the last few years in later versions of Excel?
Here is another possible solution, although it requires the LET() function which is only available to newer version of excel (2021, 365 and later I believe).
The solution would be the following formula:
=LET(
sales,A2:A50,
inventory,A1,
cum_sum,MMULT(SEQUENCE(1,ROWS(sales),1,0),(ROW(sales)<=TRANSPOSE(ROW(sales)))*sales),
week_full,MATCH(TRUE,inventory<cum_sum,0) - 1,
week_frac,(inventory - INDEX(cum_sum,week_full)) / INDEX(sales,week_full + 1),
week_full + week_frac
)
Explanation
Given inventory and the forward looking sales estimates, the formula calculates the running total (i.e. cumulated sum) of the sales estimates as shown in the table here below
Inv and Sales
Cumulated Sum
Inv > Cum_Sum
Week
100
25
25
0
1
30
55
0
2
10
65
0
3
40
105
1
4
90
195
1
5
...
...
1
6
The formula goes on to get the number of full weeks of 'forward cover' by finding the the value for the cumulated sum that exceeds the inventory minus one (here 4 - 1 = 3).
Lastly, for the value of the week fraction covered in the last week, the formula calculates inventory minus sum of sales estimates of all previous weeks divided by sales estimate of final week of cover (i.e. (100 - 65) / 40 = 0.875).
Edit
After simplifying the formula you used with the LET() function, I noticed it's doing exactly the same calculation with the only difference of how the cumulated sum is being calculated. Here's your formula using LET():
=LET(
sales,A2:A50,
inventory,A1,
cum_sum,SUBTOTAL(9,OFFSET(sales,,,SEQUENCE(ROWS(sales)))),
week_full,MATCH(TRUE,cum_sum>inventory,0)-1,
week_frac,(inventory - INDEX(cum_sum,week_full)) / INDEX(sales,week_full+1),
week_full + week_frac
)
=LET(inv,A1,
sales,A2:A6,
cs,SCAN(0,sales,LAMBDA(x,y,x+y)),
m,XMATCH(A1,cs,1)-1,
m+(inv-
IF(m=0,
0,
INDEX(cs,m)))
/INDEX(sales,m+1))
SCAN() is perfect for creating a cumulative sum.
It can be referenced inside XMATCH because of the use of LET.
Here m returns the number of full weeks and the final calculation is the number of full weeks + (inv- cumulative sum up to the full week)/sales of the following week.

price calculations weighted values

After a bit of advice on doing a calculator with a sliding scale.
I am building a matrix where we have set price points at intervals based on qty of items. The code I use works fine apart from the first 2 ranges.
Because for 1 qty the unit cost is so high my maths won't work.
Example
Qty 1 = £23.25 (Price per unit is then £23.25)
Qty 10 = £51.59 (Price per unit is then £5.159)
I then have further quantity's that work out correctly.
What I need to be able to do is some sort of weighted value, for 2 off the unit price needs to be near the £20 a unit mark, then 3 off less etc until I get to 10 off # £5.159 a unit.
(It costs more for lesser quantity's, we want to encourage more qty)
Has anyone implemented something like this? From 10 qty onwards the calculation is fine as the unit cost changes are not much at all.
Thanks
Assuming you have quantities form 1 to 10, in column A, put 23.25 in B1 and 51.59 in B10, then the following formula in B2:
=B1+(B$10-B$1)/9
And populate down to B9
in C1 use the following formula:
=B1/A1
and populate down. Final result should look like this:
You could use vlookup with a table as so:

Excel sum based on lookup of code and values in another table

Given 2 named tables in Excel 2013 (or higher):
tblInvoice
ID InvRef Total
1 I/123 45
2 I/234 8
tblDeliveries
ID InvRef Amt
1 I/123 10
2 I/123 15
3 I/123 20
4 I/234 5
5 I/234 3
How can we get the tblInvoice[Total] to compute automatically using an Excel formula? i.e. in pseudocode:
tblDeliveries[Total] = SUM(tblDeliveries[Amt] WHERE MATCH InvRef)
I have tried this Excel formula in tblInvoice[InvTotal] but it is returning an incorrect value:
=SUMPRODUCT(SUMIF(tblDeliveries[InvRef],[InvRef],tblDeliveries[Amt]))
Also tried swapping the first and second parameters. Produces a different amount, but still incorrect:
=SUMPRODUCT(SUMIF([InvRef],tblDeliveries[InvRef],tblDeliveries[Amt]))
If relevant, it is assumed that there is a 1:N relationship from tblInvoice[InvRef]:tblDeliveries[InvRef] and that tblInvoice[InvRef] is UNIQUE.
The syntax is incorrect for what you require.
=SUMPRODUCT(SUMIF(tblDeliveries[InvRef],[#InvRef],tblDeliveries[Amt]))
The # is the crucial difference.
Regards

(Excel)Calculating costs, where prices differ based on quantities

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. /(^_^)

Need to make a calculation based on multiple lookup results on another Excel sheet

Need to try and get a result based on possible 3 lookups in Excel.
I have a price for a certain size hire vehicle and need to check to see if I want to add in a supplement or not based on entry into a cell in another sheet.
I have a sheet called Keys that has the criteria I base my calculations on and a second sheet I have the rates loaded for all the vehicle sizes available, cars to coaches. I would like to calculate the supplement for customers of the move to a larger vehicle or even a reduction dependent on what I choose.
Keys data is:
Vehicle Sizes
Range # Seats Rate Column Supplement Range to work on
1 4 R N
2 7 S Y 1
3 16 T N
4 24 U Y 5
5 29 V N
6 35 W N
7 45 X N
So for example if the I have chosen to calculate the supplement on the 7 seater then I want to calculate the difference between the 7 seater and 4 seater and that is my supplement. I have also chosen to calculate the reduction between the 29 and 24 seater vehicles.
Am trying to figure out how to combine multiple IF and LOOKUP, if they are correct or not.
So basically IF I have a Y in the supplement column on Keys then calculate the difference in the rates based on the Rate Column based on the Range to work on.
Any suggestions or help appreciated
Sorry think I forgot about the actual rates. They are stored on another sheet as per below. the charges are per service, like an airport transfer etc., they are in VN Dong so thats why they are in the 100,000 + range.
R S T U V W X
Rate with Surcharge
4 7 16 24 29 35 45
340000 373000 394000 735000 780000 1050000 1210000
I have tried to tweak the answer from pnuts but getting a bit lost, note sure if I need the MATCH in the formula of not.
I doubt this will suit but it may help to clarify your requirements:
=IF($D2="N","",INDEX(Sheet2!$Q$2:$X$4,MATCH(F$1,Sheet2!$Q$2:$Q$4,0),CODE($C2)-80)-INDEX(Sheet2!$Q$2:$X$4,MATCH(F$1,Sheet2!$Q$2:$Q$4,0),CODE($C2)+$E2-$A1-81))
in F2 copied across and down to suit.

Resources