formulastreak

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

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.

Saturday bakery stall · edit D2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultD2 = $91.00
ABCD
1ItemSoldPriceTotal
2Sourdough loaf14$6.50$91.00
3Croissant32$2.80
4Cinnamon bun21$3.20
5Baguette18$3.00
6Rye loaf9$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. 1. LAMBDA: Describes your own function: given Q and P, it works out Q times P.
    • parameter = `Q`: a name for each input and `p`
    • calculation = `P`: what to work out with them
    • calculation = `Q*P`: what to work out with them
  2. 2. LAMBDA call: Runs the LAMBDA from the result of step 1 with B2 and C2.
    • 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

ArgumentRequiredWhat it is
parameter1, parameter2, …NoNames for the inputs, like q and p. Microsoft allows up to 253 of them. Names can't look like cell addresses.
calculationYesThe 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

  • #CALC!: The LAMBDA is never called: it describes a function but nothing gives it values.
  • #VALUE!: It's called with more or fewer values than it has parameters.
  • #NAME?: The file is open in a version without LAMBDA (Excel 2021 or older).

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.

Practise LAMBDA on a live sheet

Lesson 42, LAMBDA (Unit 12, LET and LAMBDA), has 7 graded exercises, checked instantly, with steps and hints when you're stuck. Pro