Creating a Formula in a Single Cell with LAMBDA

SelamT

New Member
Joined
Oct 4, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hello,

I have a formula with several steps to find the gross of the net wage. for this to happen, I need to use the "Circular Reference". In my research, I found out that it is possible to write recursive formulas with the LAMBDA function and that the "circular reference" option is not needed (I may have misunderstood)

For example, can I find the gross of net pay by typing multiple formulas I have typed in separate cells below, in just one Excel cell (without using a circular reference)?

recursive_maas.xlsx
ABCDEFG
1MonthNetDayGrossBaseSocialUnemployment
2117002,123020.002,5020002,52800,35200,03
Sheet1
Cell Formulas
RangeFormula
D2D2=B2+F2+G2
E2E2=IF(D2>150018.9,150018.9,D2)
F2F2=ROUND(E2*14%,2)
G2G2=ROUND(E2*1%,2)


Thanks,
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You may not require Lambda.
Please check the following.

Lambda 2024.xlsm
ABCDEFG
1NetGrossSocialUnemployment
217,002.1320,002.512,800.35200.03
350,000.0058,823.558,235.30588.24
4127,516.06150,018.9421,002.651,500.19
5300,000.00322,502.8421,002.651,500.19
617,002.1320,002.512,800.35200.03
750,000.0058,823.558,235.30588.24
8127,516.06150,018.9421,002.651,500.19
9300,000.00322,502.8421,002.651,500.19
10
1e
Cell Formulas
RangeFormula
F2:F9F2=MIN(D2*0.14,150018.9*0.14)
G2:G9G2=MIN(D2*0.01,150018.9*0.01)
D2:D5D2=IF(B2<UAmt,B2*Num,B2+21002.65+1500.19)
D6:D9D6=GrossCalc(B6)
Lambda Functions
NameFormula
GrossCalc=LAMBDA(refNet,LET(n, refNet,IF(n<127516.07,n*Num,n+21002.65+1500.19)))
 
Upvote 0
Lambda 2024.xlsm
ABCDEFG
1NetGrossSocialUnemployment
217,002.1220,002.492,800.35200.02
350,003.0058,827.068,235.79588.27
4127,516.10150,018.9421,002.651,500.19
5300,000.00322,502.8421,002.651,500.19
617,002.1220,002.492,800.35200.02
750,000.0058,823.538,235.29588.24
8127,516.10150,018.9421,002.651,500.19
9300,000.00322,502.8421,002.651,500.19
1e
Cell Formulas
RangeFormula
F2:F9F2=ROUND(MIN(D2*0.14,21002.65),2)
G2:G9G2=ROUND(MIN(D2*0.01,1500.19),2)
D2:D5D2=IF(B2<127516.09,B2*1.17647059285,B2+21002.65+1500.19)
D6:D9D6=GrossCalc(B6)
Lambda Functions
NameFormula
GrossCalc=LAMBDA(refNet,LET(n, refNet,Num,1.17647059285,IF(n<127516.09,n*Num,n+21002.65+1500.19)))
 
Upvote 0
Hello @Dave Patton,

First of all, thank you for your answers.
However, I could not understand the reasons for the numbers you used in the formulas.
The number that can only be used in the formula should be 150018.9. If the gross to be found is greater than 150018.9, this figure should be taken as the basis for the rates to be applied to social security and unemployment premiums.

I just want a function to write =GrossCalc(B2;C2) and find the gross wage.

Thanks,
 
Upvote 0
Did you try either the formulas or the Lambda?
N.B. You can paste the example into a clean sheet.
Click on the icon below the f(x) in the heading, move to your sheet and paste into cell A1.

To use the Lambda, use Name Manager copy the information
=new put GrossPay or a name that you prefer GrossCalc should be OK
value = the Lambda information

Lambda 2024.xlsm
ABCDEFG
1NetGrossSocialUnemployment
2100,000.00117,647.0616,470.591,176.47
3400,000.00422,502.8421,002.651,500.19
1e
Cell Formulas
RangeFormula
F2:F3F2=ROUND(MIN(D2*0.14,21002.65),2)
G2:G3G2=ROUND(MIN(D2*0.01,1500.19),2)
D2:D3D2=GrossCalc(B2)
Lambda Functions
NameFormula
GrossCalc=LAMBDA(refNet,LET(n, refNet,Num,1.17647059285,IF(n<127516.091,n*Num,n+21002.65+1500.19)))
 
Upvote 0
GrossCalc prompts for the reference cell (refNet) and then calculates the Gross Pay.

Does it work for you? The formula that does not use Lambda also works.

Lambda 2024.xlsm
ABCD
1NetGross
2100,000.00117,647.06
345,000.0052,941.18
41,000,000.001,022,502.84
5 or
6500,000.00522,502.84
745,000.0052,941.18
8100,000.00117,647.06
1e
Cell Formulas
RangeFormula
D2:D4D2=GrossCalc(B2)
D6:D8D6=IF(B6<127516.09,B6*1.17647059285,B6+21002.65+1500.19)
Lambda Functions
NameFormula
GrossCalc=LAMBDA(refNet,LET(n, refNet,Num,1.17647059285,IF(n<127516.091,n*Num,n+21002.65+1500.19)))
 
Upvote 0
Yes, I tried both of your formulas. Thank you.

I just don't understand the numeric values you defined in LAMBDA, because there shouldn't be a numeric value like that. Only ratios like 0.14 and 0.1 can be used.

If a net figure is greater than 150018.90, the ratios 0.14 and 0.1 should be applied to 150018.90.
 
Upvote 0
The suggestions that I provided work.
The Social and Unemployment are calculated on the Gross.
Try reviewing the example with Formulas Evaluate.
 
Upvote 0
I guess you did not understand what I meant :( I am saying that you should not use fixed numbers in the formula.

I am writing you a UDF, this code does what I want. However, I want to do it with a formula using LAMBDA, not with vba. My goal is to learn how to use LAMBDA.

VBA Code:
Function CalculateGrossSalary(NetSalary As Double) As Double
    Const SocialSecurityRate As Double = 0.14
    Const UnemploymentRate As Double = 0.01
    Const MaximumSalary As Double = 150018.9

    Dim EstimatedGross As Double
    Dim CalculatedNet As Double
    Dim Difference As Double

    EstimatedGross = NetSalary

    Do
        Dim SSK As Double, Unemployment As Double
        SSK = WorksheetFunction.Round(WorksheetFunction.Min(EstimatedGross, MaximumSalary) * SocialSecurityRate, 2)
        Unemployment = WorksheetFunction.Round(WorksheetFunction.Min(EstimatedGross, MaximumSalary) * UnemploymentRate, 2)
        CalculatedNet = EstimatedGross - SSK - Unemployment

        Difference = NetSalary - CalculatedNet

        If Abs(Difference) < 0.0001 Then Exit Do

        EstimatedGross = EstimatedGross + Difference
    Loop

    CalculateGrossSalary = EstimatedGross
End Function
 
Upvote 0
You can review samples of Lambdas with Recursion in the Lambda section of this forum.
There are also examples on the internet.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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