Logic and errors function
LAMBDA function in Google Sheets and Excel
LAMBDA defines your own function from named inputs and a calculation, which you call with values or save under a name.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
LAMBDA([parameter1, parameter2, …,] calculation)Arguments in [brackets] are optional. Google Sheets writes it LAMBDA(name, formula_expression).
Example
=LAMBDA(q,p,q*p)(B2,C2) reads: Define a function with inputs q and p that returns q*p, and call it straight away with the quantity in B2 and the price in C2.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Item | Sold | Price | Total |
| 2 | Sourdough loaf | 14 | $6.50 | $91.00 |
| 3 | Croissant | 32 | $2.80 | |
| 4 | Cinnamon bun | 21 | $3.20 | |
| 5 | Baguette | 18 | $3.00 | |
| 6 | Rye loaf | 9 | $7.00 |
D2 shows $91.00: the LAMBDA multiplies q = 14 by p = 6.50.
How the spreadsheet calculates it
Runs the LAMBDA from the result of LAMBDA (step 1) with B2 and C2.
- 1. LAMBDA: Describes your own function: given
QandP, it works outQtimesP.parameter=`Q`: a name for each input and `p`calculation=`P`: what to work out with themcalculation=`Q*P`: what to work out with them
- 2. LAMBDA call: Runs the LAMBDA from the result of step 1 with
B2andC2.value 1=`B2`:value 2=`C2`:
More LAMBDA examples
=LAMBDA(x,x*1.2)(C2)The price in C2 plus 20%: $7.80 for the sourdough loaf.=LAMBDA(q,p,ROUND(q*p,2))(B2,C2)A line total rounded to cents.=MAP(B2:B6,C2:C6,LAMBDA(q,p,q*p))The line total for every row at once.=LAMBDA(t,LET(n,TRIM(t),PROPER(n)))(A2)A clean-up function: trim, then capitalise.
Paste any of these into the formula explainer to see it step by step.
Tips
- Test the LAMBDA in a cell with values in brackets before you name it.
- Use short, clear parameter names that can't be read as cells.
- Keep rates and settings as parameters or cell references, not numbers typed inside the calculation.
What LAMBDA is used for
Turning a calculation a team repeats everywhere (a commission rule, a tax line, a clean-up step) into one named function, and running a calculation on every row or step with MAP, BYROW and SCAN.
Arguments
| Argument | Required | What it is |
|---|---|---|
| parameter1, parameter2, … | No | Names for the inputs, like q and p. Microsoft allows up to 253 of them. Names can't look like cell addresses. |
| calculation | Yes | The formula to work out with those names; always the last argument. |
Common mistakes
Leaving the LAMBDA uncalled: #CALC!.
Giving it the wrong number of values: #VALUE!.
Using a parameter name that looks like a cell address, such as tax1 or q3: pick names like qty and price.
Writing a long LAMBDA directly into many cells: save it once under a name (Name Manager in Excel) and call it by that name, so a fix applies everywhere.
In Google Sheets
Google Sheets has LAMBDA, written LAMBDA(name, formula_expression) in Google's help: the same idea of names followed by a calculation, called with values in brackets after it. Saving a LAMBDA under a name works differently in each app; in Excel it's done in the Name Manager.
Errors you may see with LAMBDA
Questions
How do I make a custom function in Excel without VBA?
Write a LAMBDA, test it by calling it in a cell, then give it a name in the Name Manager with the LAMBDA as the value. After that, =LINETOTAL(B2,C2) works like a built-in function in that workbook. See the LAMBDA guide.
Why does my LAMBDA show #CALC!?
Because it isn't called. A LAMBDA on its own is only a description; add the values in brackets after it, like LAMBDA(x,x*2)(5), or use it inside MAP, BYROW or SCAN.
What's the difference between LET and LAMBDA?
LET names values inside one formula; LAMBDA names inputs, so the same calculation can run on different values. They work well together: a LET inside a LAMBDA keeps a long custom function readable.
Sources
Official documentation the facts on this page were checked against.