explanation please

Holger

Board Regular
Joined
Nov 22, 2017
Messages
58
Office Version
  1. 365
Platform
  1. MacOS
Hi everyone,

I have found the below LET formula to calculate income tax in cell F2. While it works, I struggle to comprehend the Lambda part. Lambda uses income, start, end, rate as input. income refers to cell E2. What I don't understand is, how can the function calculate correct tax, if start, end, rate are nowhere defined.

What am I missing?

Thanks for anyone's help.

Book7
ABCDEF
1LowHighRateincometax
2010,00010%82,50015,030
31,00140,00012%
440,00185,00022%
585,001160,00024%
6160,00132%
Sheet1
Cell Formulas
RangeFormula
F2F2=LET( income, E2, brackets, A2:C6, bracketStart, INDEX(brackets, 0, 1), bracketEnd, INDEX(brackets, 0, 2), taxRate, INDEX(brackets, 0, 3), numBrackets, ROWS(brackets), taxCalculation, LAMBDA(income,start,end,rate, IF(income > start, MIN(income - start, end - start) * rate, 0) ), totalTax, SUM( MAP(bracketStart, bracketEnd, taxRate, LAMBDA(start,end,rate, taxCalculation(income, start, end, rate)) ) ), totalTax )
 
@Peter_SSs firstly, sorry about not using the formula tag.....still getting the hang of everything on this forum.

Below is the latest version and it looks there are still some queries:

* I have inserted manual calls for the 2 values you suggested (L2 and P2 blocks)
* I have aligned the brackets
* I added a new formula version in H3
* F2 and F3 still show minor differences
* to match to manual calls simply change E2 to either value

Book9
ABCDEFGHIJKLMNOPQR
1LowHighRateincometax
2010,00010%82,49913,949.78HolgerIncomeRateTaxManual 82,499Manual 163,000
310,00040,00012%13,950.00Peter10,00010%1,00010,00010%1,00010,00010%1,000
440,00085,00022%30,00012%3,60030,00012%3,60030,00012%3,600
585,000160,00024%42,49922%9,35042,49922%9,35045,00022%9,900
6160,000100,000,00032%024%0075,00024%18,000
7032%03,00032%960
882,49913,949.7882,49913,949.78163,00033,460.00
Sheet1
Cell Formulas
RangeFormula
H2:J8H2=LET( income,E2, brackets,A2:C6, bracketStart,INDEX(brackets,0,1), bracketEnd,INDEX(brackets,0,2), taxRate,INDEX(brackets,0,3), income_by_bracket,IF(income<=bracketStart,0, IF(income>bracketEnd,bracketEnd-bracketStart,income-bracketStart)), tax_by_bracket,income_by_bracket*taxRate, VSTACK( HSTACK("Income","Rate","Tax"), HSTACK(income_by_bracket,taxRate,tax_by_bracket), HSTACK(SUM(income_by_bracket),"",SUM(tax_by_bracket) )))
F2F2=LET( income, E2, brackets, A2:C6, bracketStart, INDEX(brackets, 0, 1), bracketEnd, INDEX(brackets, 0, 2), taxRate, INDEX(brackets, 0, 3), numBrackets, ROWS(brackets), taxCalculation, LAMBDA(income,start,end,rate, IF(income >start, MIN(income - start, end - start) * rate, 0) ), totalTax, SUM( MAP(bracketStart, bracketEnd, taxRate, LAMBDA(start,end,rate, taxCalculation(income, start, end, rate)) ) ), totalTax )
F3F3=LET(income,E2,low,A2:A6,high,B2:B6,rate,C2:C6,totalTax,SUM(FILTER((high-low+1)*rate,high<=income,0)) +(income-MAXIFS(high,high,"<="&income))*MINIFS(rate,high,">="&income),totalTax)
L5L5=M2-A4
N3:N6,R3:R7N3=+M3*L3
L8,R8,P8,N8L8=SUM(L3:L7)
P7P7=+Q2-A6
Dynamic array formulas.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Below is the latest version and it looks there are still some queries:
Yes, it is still not right. My formula is irrelevant because you have changed the initial table in multiple ways. My formula is designed for the original table layout with only the two changes I had mentioned:
For consistency and accuracy is does require the first bracket to start with a 1 (all the other brackets start with a "...1" number) and some large number for the high of the top bracket
If you test on a fresh sheet with that table and my formula I think you will find the results accurate.

I have not yet had a chance to study/test your new formula. Will do that in a day or so when I have some more time.
 
Upvote 0
I have not yet had a chance to study/test your new formula.
The new formula seems to be working fine. My preference though would be to have the initial brackets table reflect the actual low and high figures, assuming that the Income would always be a whole number. If that is the case then, for example, 10,000 is not the actual low value for the 12% bracket.

A couple of small tweaks to your formula would allow for that though. Below,
- your table & formulas in the top section,
- my table, F12 formula and my tweak of your formula in H12.

Holger.xlsm
ABCDEFGHIJ
1LowHighRateincometax
2010,00010%82,49913,949.78IncomeRateTax
310,00040,00012%10,00010%1,000.00
440,00085,00022%30,00012%3,600.00
585,000160,00024%42,49922%9,349.78
6160,000100,000,00032%024%0.00
7032%0.00
882,49913,949.78
9
10
11LowHighRateincometax
12110,00010%82,49913,949.78IncomeRateTax
1310,00140,00012%10,00010%1,000.00
1440,00185,00022%30,00012%3,600.00
1585,001160,00024%42,49922%9,349.78
16160,001100,000,00032%024%0.00
17032%0.00
1882,49913,949.78
Tax (4)
Cell Formulas
RangeFormula
F2F2=LET( income, E2, brackets, A2:C6, bracketStart, INDEX(brackets, 0, 1), bracketEnd, INDEX(brackets, 0, 2), taxRate, INDEX(brackets, 0, 3), numBrackets, ROWS(brackets), taxCalculation, LAMBDA(income,start,end,rate, IF(income >start, MIN(income - start, end - start) * rate, 0) ), totalTax, SUM( MAP(bracketStart, bracketEnd, taxRate, LAMBDA(start,end,rate, taxCalculation(income, start, end, rate)) ) ), totalTax )
H2:J8H2=LET( income,E2, brackets,A2:C6, bracketStart,INDEX(brackets,0,1), bracketEnd,INDEX(brackets,0,2), taxRate,INDEX(brackets,0,3), income_by_bracket,IF(income<=bracketStart,0, IF(income>bracketEnd,bracketEnd-bracketStart,income-bracketStart)), tax_by_bracket,income_by_bracket*taxRate, VSTACK( HSTACK("Income","Rate","Tax"), HSTACK(income_by_bracket,taxRate,tax_by_bracket), HSTACK(SUM(income_by_bracket),"",SUM(tax_by_bracket) )))
E12E12=E2
F12F12=LET(income,E12,low,A12:A16,high,B12:B16,rate,C12:C16,totalTax,SUM(FILTER((high-low+1)*rate,high<=income,0)) +(income-MAXIFS(high,high,"<="&income))*MINIFS(rate,high,">="&income),totalTax)
H12:J18H12=LET( income,E12, brackets,A12:C16, bracketStart,INDEX(brackets,0,1), bracketEnd,INDEX(brackets,0,2), taxRate,INDEX(brackets,0,3), income_by_bracket,IF(income<bracketStart,0, IF(income>=bracketEnd,bracketEnd-bracketStart+1,income-bracketStart+1)), tax_by_bracket,income_by_bracket*taxRate, VSTACK( HSTACK("Income","Rate","Tax"), HSTACK(income_by_bracket,taxRate,tax_by_bracket), HSTACK(SUM(income_by_bracket),"",SUM(tax_by_bracket) )))
Dynamic array formulas.
 
Upvote 0
Don't know if you might be interested but a simpler way to calculate the actual tax would be to add a column to the initial table and then use a much simpler formula to calculate the tax.

Holger.xlsm
ABCDEF
21LowHighRateBaseincometax
22110,00010%082,49913,949.78
2310,00140,00012%1000
2440,00185,00022%4600
2585,001160,00024%14500
26160,001100,000,00032%32500
Tax (4)
Cell Formulas
RangeFormula
F22F22=LET(b,INDEX(A22:D26,MATCH(E22,A22:A26),0),TAKE(b,,-1)+(E22-TAKE(b,,1)+1)*INDEX(b,3))
D23:D26D23=SUMPRODUCT(B$22:B22-A$22:A22+1,C$22:C22)
 
Upvote 0
Thanks Peter, much appreciated your thoughts and experience. Let and Lambda are still posing huge learning curves for me especially when wrapped with other functions. Each time I see one I have to break each component down into separate cells and see the result so I can understand what each step does and how the final output is achieved. Feedback like yours and others through diff versions feeds the learning process…. Slowly in my end 😉

Thanks again
 
Upvote 0
@Peter_SSs ...I'm still struggling to get your latest simplified formula to work. Please see below.

* Your simplified formula from post #14 is Option 5 in cell F21
* I have deconstructed it in cells N11:Q22
* My result is tax of approx. 23k
* I think the issue is, that N13 picks up the 3rd row in the array (14,500) instead of row 2 with 4,600

Any chance to have a look please.

Thanks again for any help.

LET Function - Tax 1.xlsx
ABCDEFGHIJKLMNOPQ
1LowHighRateBase Taxincome
2010,00010%1,00082,499
310,00040,00012%4,600
440,00085,00022%14,500
585,000160,00024%32,500
6160,000100,000,00032%
7
8
9
10
11Result as sum onlyResult as table40,00085,0000.2214,500
12
13Option 113,949.78IncomeRateTax14,5003
1410,00010%1,000
15Option 213,949.7830,00012%3,60042,500
1642,49922%9,350
17Option 313,949.78024%00.22
18032%0
19Option 413,949.7882,49913,949.789,350
20
21Option 523,849.78
2223,850.00
Sheet1
Cell Formulas
RangeFormula
D2:D5D2=SUMPRODUCT(B$2:B2-A$2:A2,C$2:C2)
N11:Q11N11=INDEX(A2:D6,MATCH(E2,A2:A6),0)
F13F13=LET( income, E2, brackets, A2:C6, bracketStart, INDEX(brackets, 0, 1), bracketEnd, INDEX(brackets, 0, 2), taxRate, INDEX(brackets, 0, 3), numBrackets, ROWS(brackets), taxCalculation, LAMBDA(income,start,end,rate, IF(income >start, MIN(income - start, end - start) * rate, 0) ), totalTax, SUM( MAP(bracketStart, bracketEnd, taxRate, LAMBDA(start,end,rate, taxCalculation(income, start, end, rate)) ) ), totalTax )
H13:J19H13=LET( income,E2, brackets,A2:C6, bracketStart,INDEX(brackets,0,1), bracketEnd,INDEX(brackets,0,2), taxRate,INDEX(brackets,0,3), income_by_bracket,IF(income<=bracketStart,0, IF(income>bracketEnd,bracketEnd-bracketStart,income-bracketStart)), tax_by_bracket,income_by_bracket*taxRate, VSTACK( HSTACK("Income","Rate","Tax"), HSTACK(income_by_bracket,taxRate,tax_by_bracket), HSTACK(SUM(income_by_bracket),"",SUM(tax_by_bracket) )))
N13N13=TAKE(INDEX(A2:D6,MATCH(E2,A2:A6),0),,-1)
O13O13=MATCH(E2,A2:A6)
F15F15=LET( income,E2, low,A2:A6, high,B2:B6, rate,C2:C6, totalTax,SUM(FILTER((high-low)*rate,high<=income,0)) +(income-MAXIFS(high,high,"<="&income))*MINIFS(rate,high,">="&income), totalTax)
N15N15=(E2-TAKE(INDEX(A2:D6,MATCH(E2,A2:A6),0),,1)+1)
F17F17=LET( income, E2, brackets, A2:C6, bracketStart, INDEX(brackets, 0, 1), bracketEnd, INDEX(brackets, 0, 2), taxRate, INDEX(brackets, 0, 3), income_by_bracket,IF(income<=bracketStart,0, IF(income>bracketEnd,bracketEnd-bracketStart,income-bracketStart)), tax_by_bracket,income_by_bracket*taxRate, SUM(tax_by_bracket) )
N17N17=INDEX(INDEX(A2:D6,MATCH(E2,A2:A6),0),3)
F19F19=LET( income,E2, tax_rates, C2:C6, upper,B2:B6, lower,DROP(VSTACK(0,upper),-1), income_by_bracket,IF(income<=lower,0, IF(income>upper,upper-lower,income-lower)), tax_by_bracket,income_by_bracket*tax_rates, SUM(tax_by_bracket) )
N19N19=+N15*N17
F21F21=LET(b,INDEX(A2:D6,MATCH(E2,A2:A6),0),TAKE(b,,-1)+(E2-TAKE(b,,1))*INDEX(b,3))
N22N22=+N13+N19
Dynamic array formulas.
 
Upvote 0
please ignore my last post. I resolved it already. Had the base tax amount in the wrong row. 🙈
 
Upvote 0
Had the base tax amount in the wrong row.
That it. :)
Your choice of course, but I would still revert the table to have accurate figures in the "Low' column as, for example,10,000 does not belong in the second bracket in my view.


Your simplified formula from post #14 is Option 5 in cell F21
Not quite - apart from modifying it for the different range the table is in, you have also modified it (removed a +1) due to my point above about the different 'Low' values.
 
Upvote 0
@Peter_SSs I knew that issue would come up again 😉 so I added it back in and it should now work with all options showing the same result. Below is the final one incl. the deconstruction for others to learn form if needed.

Thanks again

Let Function - Tax 1.xlsx
ABCDEFGHIJKLMNO
1LowHighRateBase TaxIncome
2110,00010%082,499
310,00140,00012%1,000
440,00185,00022%4,600
585,001160,00024%14,500
6160,001100,000,00032%32,500
7
8
9
10
11Result as sum onlyResult as tableDeconstruct of cell F21
12
13Option 113,949.78IncomeRateTax40,00185,0000.224,600
1410,00010%1,000
15Option 213,949.7830,00012%3,6004,600
1642,49922%9,350
17Option 313,949.78024%042,499
18032%0
19Option 413,949.7882,49913,949.780.22
20
21Option 513,949.789,349.78
22
2313,949.78
Sheet1
Cell Formulas
RangeFormula
D3:D6D3=SUMPRODUCT(B$2:B2-A$2:A2+1,C$2:C2)
F13F13=LET( income, E2, brackets, A2:C6, bracketStart, INDEX(brackets, 0, 1), bracketEnd, INDEX(brackets, 0, 2), taxRate, INDEX(brackets, 0, 3), numBrackets, ROWS(brackets), taxCalculation, LAMBDA(income,start,end,rate, IF(income >start, MIN(income - start+1, end - start+1) * rate, 0) ), totalTax, SUM( MAP(bracketStart, bracketEnd, taxRate, LAMBDA(start,end,rate, taxCalculation(income, start, end, rate)) ) ), totalTax )
H13:J19H13=LET( income,E2, brackets,A2:C6, bracketStart,INDEX(brackets,0,1), bracketEnd,INDEX(brackets,0,2), taxRate,INDEX(brackets,0,3), income_by_bracket,IF(income<=bracketStart,0, IF(income>bracketEnd,bracketEnd-bracketStart+1,income-bracketStart+1)), tax_by_bracket,income_by_bracket*taxRate, VSTACK( HSTACK("Income","Rate","Tax"), HSTACK(income_by_bracket,taxRate,tax_by_bracket), HSTACK(SUM(income_by_bracket),"",SUM(tax_by_bracket) )))
L13:O13L13=INDEX(A2:D6,MATCH(E2,A2:A6),0)
F15F15=LET( income,E2, low,A2:A6, high,B2:B6, rate,C2:C6, totalTax,SUM(FILTER((high-low+1)*rate,high<=income,0)) +(income-MAXIFS(high,high,"<="&income))*MINIFS(rate,high,">="&income), totalTax)
L15L15=TAKE(INDEX(A2:D6,MATCH(E2,A2:A6),0),,-1)
F17F17=LET( income, E2, brackets, A2:C6, bracketStart, INDEX(brackets, 0, 1), bracketEnd, INDEX(brackets, 0, 2), taxRate, INDEX(brackets, 0, 3), income_by_bracket,IF(income<=bracketStart,0, IF(income>bracketEnd,bracketEnd-bracketStart+1,income-bracketStart+1)), tax_by_bracket,income_by_bracket*taxRate, SUM(tax_by_bracket) )
L17L17=(E2-TAKE(INDEX(A2:D6,MATCH(E2,A2:A6),0),,1)+1)
F19F19=LET( income,E2, tax_rates, C2:C6, upper,B2:B6, lower,DROP(VSTACK(0,upper),-1), income_by_bracket,IF(income<=lower,0, IF(income>upper,upper-lower,income-lower)), tax_by_bracket,income_by_bracket*tax_rates, SUM(tax_by_bracket) )
L19L19=INDEX(INDEX(A2:D6,MATCH(E2,A2:A6),0),3)
F21F21=LET(b,INDEX(A2:D6,MATCH(E2,A2:A6),0),TAKE(b,,-1)+(E2-TAKE(b,,1)+1)*INDEX(b,3))
L21L21=+L17*L19
L23L23=+L15+L21
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,226,116
Messages
6,189,054
Members
453,523
Latest member
Don Quixote

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