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 )
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Holger,

In your formula, the first LAMBDA is defined as a new method (aka function) which need an income, a start, an end and a rate. This new method is called by using the name 'taxCalculation'. This LAMBDA will then get its arguments values when it will be called.

Once this new method is defined, you are using another LAMBDA with only start, end and rate arguments. Those arguments are then going to be passed to the method 'taxCalculation' previously defined with the 'income' variable which has been defined in first row of the LET. This LAMBDA associated to totalTax variable will get the arguments values from the MAP function which loop the bracketStart, bracketEnd and taxRate arrays. totalTax could be read like so:
  1. Do the SUM of :
    1. For each item in backetStart, bracketEnd and taxRate, pass the ith item to LAMBDA as start, end and rate argument
    2. LAMBDA, once you recieve the ith element, call the taxCalculation method using income variable and your 3 arguments
    3. next ith element
I hope I was clear enought and want to apologize in advance for typing errors since I'm french.

Bests regards,

Vincent
 
Upvote 0
Solution
Hi Holger,

In your formula, the first LAMBDA is defined as a new method (aka function) which need an income, a start, an end and a rate. This new method is called by using the name 'taxCalculation'. This LAMBDA will then get its arguments values when it will be called.

Once this new method is defined, you are using another LAMBDA with only start, end and rate arguments. Those arguments are then going to be passed to the method 'taxCalculation' previously defined with the 'income' variable which has been defined in first row of the LET. This LAMBDA associated to totalTax variable will get the arguments values from the MAP function which loop the bracketStart, bracketEnd and taxRate arrays. totalTax could be read like so:
  1. Do the SUM of :
    1. For each item in backetStart, bracketEnd and taxRate, pass the ith item to LAMBDA as start, end and rate argument
    2. LAMBDA, once you recieve the ith element, call the taxCalculation method using income variable and your 3 arguments
    3. next ith element
I hope I was clear enought and want to apologize in advance for typing errors since I'm french.

Bests regards,

Vincent
Merci beaucoup Vincent 😉. What I was missing is, that the first Lambda call is merely the definition and it is rather the 2nd Lambda with the MAP that provides the input parameters...... Thanks again.
 
Upvote 0
While it works,
What am I missing about how the tax should be calculated?

25 01 29.xlsm
ABCDEFG
1LowHighRateIncome in bracketTax in bracketincometax
2010,00010%10,0001,00082,50015,030
31,00140,00012%30,0003,600
440,00185,00022%42,5009,350
585,001160,00024%00
6160,00132%00
782,50013,950
Tax
Cell Formulas
RangeFormula
G2G2=LET( income, F2, 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 )
E2:E6E2=D2*C2
D7:E7D7=SUM(D2:D6)
 
Upvote 0
Thanks Peter for the follow up. I marked this already as solved but it does not seem to stick to the post. Secondly, my table above had an error, where cell A3 should read 10,001 instead of 1,001. Tax will then be correctly calucated. Vincent feedback helped me with better understanding the entire formula. Thanks again.
 
Upvote 0
I marked this already as solved but it does not seem to stick to the post.
Post #2 is marked as the solution so that is fine. I just couldn't see that the formula gave the correct solution but I was just blind to that obvious typo. I just looked at the 'High' column to see what was in the brackets. :cool:
 
Upvote 0
Despite my poor reading earlier, I still question the accuracy of your formula. In a number of cases I think it is slightly ($1) out. Try your formula and a manual calculation with say $163,000 or $82,499

Also wondering if you would contemplate a considerably shorter approach. 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 - or this could be built into the formula if required.

25 01 29.xlsm
ABCDEF
1LowHighRateincometax
2110,00010%82,50013,950
310,00140,00012%13,950
440,00185,00022%
585,001160,00024%
6160,001100,000,00032%
Tax
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 )
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)
 
Upvote 0
Thanks Peter and I ended up with this formula after more trial and error:

=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)
)))
 
Upvote 0
When you post a formula by itself in the forum, please use the formula tags:
1738124883706.png


Whilst that formula mostly produces approximately correct results, they are still not correct. I don't think that you did the manual calculations that I suggested previously.

If you adjust or post again, can you please do so with XL2BB so I can be sure I am looking at the same thing you are?
 
Upvote 0

Forum statistics

Threads
1,226,115
Messages
6,189,053
Members
453,522
Latest member
Seeker2025

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