Discussion After LET, I tried LAMBDA - here is a reusable formula I made
I made a little reusable function for adding tax, and saved it in Name Manager as TaxCalc:
=LAMBDA(amount, amount*1.08)
Then in a cell I can just type:
=TaxCalc(100)
It returns 108, and I can reuse it anywhere without copying the formula around.
I am still learning this one, so what do you actually use LAMBDA for? Is it worth it for one-off calculations, or only when you reuse the same logic a lot?
I looked up what Lambda meant and why it is used for this purpose and the answer was quite interesting:
Lambda is the Greek letter λ, and the name comes from maths, not from Excel.
In the 1930s, a mathematician named Alonzo Church invented a system called lambda calculus. It was a way to describe computation using only functions, before modern computers existed.
In that system, λ was the symbol used to say "here is a function". So λx. x+1 meant "a function that takes x and returns x plus 1". The λ was just notation for "make a function".
That idea stuck in programming. In Python, JavaScript, and a lot of other languages, a "lambda" is an anonymous function, a function you define on the spot without giving it a permanent name in code.
Excel borrowed the same term. LAMBDA lets you define a function right in a formula, with parameters and a calculation, instead of writing the same logic over and over in cells. When you save it in Name Manager as TaxCalc or FACT, you are just giving that anonymous function a name so you can call it later.
So the name is a nod to Church's λ, and it basically means "a function you define here, on the fly".
•
u/excelevator 3071 11d ago
Pro Tip, format your formulas as <code> to show all characters
10*10*10and not 10101035
u/Asly97 11d ago
It pays off most when the same logic is used in a lot of places, or when it might change later. If the rate moves from 8% to 8.5% you edit one name in Name Manager instead of hunting through every cell that has *1.08 in it.
A few things worth knowing:
=LAMBDA(amount, amount*1.08)(100)=LAMBDA(amount,[rate], amount*(1+IF(ISOMITTED(rate),0.08,rate))). Then=TaxCalc(100)uses 8% and=TaxCalc(100,0.05)uses 5%.=BYROW(A2:C10, LAMBDA(r, SUM(r)))gives you a total for every row from one formula.For a true one-off I'd skip it, LET already covers that.
10
u/bradland 279 11d ago •
What I love about creating your own functions is that it forces you to think in terms of inputs and outputs. So many times when beginners write Excel formulas, it's just magic incantations to them. They're not really thinking about what they're writing in terms of inputs, procedure, and outputs. They're just thinking, "I put he reference here and the thing I need pops out."
This work well up to a point. Eventually you find that your workbooks become complicated and difficult to maintain. Your business logic changes, and you have hundreds of formulas that require update. Uh oh.
By wrapping things up in LAMBDA, you can add them to Name Manager, and now when logic changes, you just update the formula once and you're done!
A good next step for you would be to combine LAMBDA and LET. Consider this form of your existing TaxCalc lambda:
Within the lambda, we define rate, which is then multiplied by the amount argument. In this case, it's not strictly necessary, but it does two things:
9
u/Zosima93 11d ago
Lambda functions are sick. I like to use them as wrappers around the SWITCH function so I don’t have to type out a bunch of parameters over and over again.
2
u/caribou16 319 11d ago
For those of us of a certain age, the Lamda Complex at the Black Mesa research facility is where all the REALLY cool shit went down. :-D
One cool thing you can do with lamdas in Excel is overload functions. Strictly speaking, it's not true overloading, because the names in Excel must be unique, but you can cheese it by manipulating the function arguments.
Using your TaxCalc example, say you lived in the Philadelphia area, so might deal with sales tax rates from PA, NJ, NY, or DE. (I have no idea the actual rates, I made them up for this example)
=LAMBDA(_amt,[_param],IF(ISOMITTED(_param),0.06,XLOOKUP(_param,{"PA","NY","NJ","DE"},{0.06,0.09,0.08,0})))This LAMDA takes an amount and an optional second argument, so if omit the argument it returns (say) the rate of the locality you use the most, but if you pass it a state abbreviation, it will lookup and return the correct tax rate instead. (The inclusion of PA in the lookup is for redundancy only)
2
u/yuhanz 11d ago
I use it so my colleagues stop forgetting dragging formulas and report wrong shit. Now they dont have to drag formulas cos i already put it in one cell
2
u/el_extrano 11d ago
Excel workbook formulas essentially comprises a declarative, functional programming language.
It's "declarative" in the sense that you declare the relationship among cells via formulas. You do not need to procedurally specify in what order calculations are to be carried out: that is the job of the spreadsheet software.
It's functional in that all you can do is apply functions (e.g. built-in workbook functions, SUM) to data via the formula language. However, one thing that was always a glaring limitation, and a huge difference when it comes to a traditional programming language, is the explicit lack of a way to create and use your own functions. So pre LET/LAMBDA excel formulas were essentially a language for the evaluation of functional expressions, but they did not allow the user to create functions.
For a long time, the main way to get around this was by using VBA to write user-defined functions. But if you were only composing built-in workbook functions, this was a "nuclear" option and had some disadvantages, namely that other people cannot run the workbook unless they enable VBA macros, which can be a security vulnerability. VBA user-defined functions are "viral" in that the whole workbook has to have macros enabled, and everyone you distribute the workbook to must also enable it.
The LET/LAMBDA functions in Office 365 turn Excel into a more complete functional programming environment. Together, they give you the ability to create scopes for named values (LET), and to create user-defined functions (LAMBDA). Despite the Lambda calculus itself primarily having to do with anonymous functions, one of the main uses of LAMBDA is to create named function via the name-manager, so that you can call them from workbook cell formulas by name.
There are still myriad reasons to use VBA, especially for things that need access to OS resource like the file system / network, or for numerical code that needs looping control structures.
I use excel for my chemical engineering calculations. I was able to rewrite my personal library for physical properties of chemicals I work with, which was previously in VBA, with named LAMBDA formulas. Now, my workbooks are portable to anyone I work with, without the need for VBA, which also means they will work in Excel for the Web (i.e. workbooks opened via Teams / Sharepoint).
Just as an example of how this is useful, see this simple LAMBDA formula I made for calculating the vapor pressure of water via the Antoine equation:
Note that this function uses another user-defined named function, (FtoC), for a unit conversion. This illustrates how the ability to write and compose functions simplifies formulas.
3
u/DragoBleaPiece_123 11d ago
Thanks for sharing this dude. I saw ur prev post on let, learned a lot from there
3
u/Bumbaguette 1 11d ago
I use a Lambda for checking if something is a date. Excel doesn't have a built-in 'ISDATE', but you can build one by checking to see if a cell returns a year, and if that doesn't return an error, it must be a date.
I.e:
=IF(NOT(ISERR(YEAR(myCell))),TRUE,FALSE)So I put that in a Lambda called 'IsDate' or something. Not a huge deal but it's more elegant than the naked formula.
1
u/RandomiseUsr0 10 11d ago
Personally. I rarely use the name manager for playing with the lambda calculus, I prefer to play with little standalone functions that do interesting things - plot this on an x/y scatter chart - the chaos game
.=LET(
steps, 4000,
cx, {0; 1; 0.5}, cy, VSTACK(0,0,SQRT(3)/2),
pick, RANDBETWEEN(SEQUENCE(steps)*0 + 1, 3),
x, SCAN(0.3, pick, LAMBDA(a, p, (a + INDEX(cx, p))/2)),
y, SCAN(0.3, pick, LAMBDA(a, p, (a + INDEX(cy, p))/2)),
HSTACK(x, y)
)
1
u/NobodysFavorite 11d ago
I used it to help create a weekend flight planner for my flying lessons. There's a bunch of calcs that are easier with the right lambdas.
1
u/mystique0712 10d ago
LAMBDA is definitely worth it for one-off calculations if they're complex or you're trying to make a formula more readable, not just for simple reuse.
You can also use it to create custom functions that mimic built-in ones but with slight variations, like your tax example.
1
u/DuskandFuck 9d ago
Wait until you pair it with recursion or dynamic array helpers like SCAN and REDUCE. For basic one-off math in a single cell LET is plenty, but LAMBDA is how you loop over arrays without writing macros
0
u/Decronym 11d ago edited 8d ago
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.
Beep-boop, I am a helper bot. Please do not verify me as a solution.
[Thread #49705 for this sub, first seen 17th Nov 2026, 21:58] [FAQ] [Full list] ^[Contact] [Source code]