Lesson 68 of 92 · Free Excel Course
Excel · Excel function reference
Excel LAMBDA Function: Syntax, Examples and Common Errors
How to build your own Excel function with LAMBDA: test it in a cell, save it in Name Manager, call it by name, and fix #CALC!, #VALUE! and #NAME?.
The LAMBDA function lets you build your own Excel function out of an ordinary formula. You give the formula named inputs (parameters), save it under a friendly name in Name Manager, and then call it like a built-in function: =TOCELSIUS(A2) instead of =(5/9)*(A2-32). It returns whatever its calculation returns, and the new function works anywhere in that workbook, with no VBA or macros. Microsoft lists LAMBDA for Excel for Microsoft 365 (Windows and Mac), Excel for the web, and Excel 2024 (Windows and Mac). Excel 2021 and earlier don't have it.
Syntax
=LAMBDA([parameter1, parameter2, ...,] calculation)
- parameter (optional): a name for an input you'll pass in when you call the function, such as
temp,aorold. The value passed can be a number, text or a cell reference. You can have up to 253 parameters, or none. Parameter names follow Excel's normal name rules, with one extra: they can't contain a period. - calculation (required): the formula to run, written with the parameter names. It must be the last argument and must return a result.
A LAMBDA does nothing until it's called. There are two ways to call it:
- Inline, to test it: put the inputs in brackets straight after it.
=LAMBDA(number, number + 1)(1)returns 2. - By name, to reuse it: on Windows go to Formulas > Name Manager, click New, type a Name, leave Scope as Workbook, add an optional Comment (up to 255 characters), paste the LAMBDA into Refers to, click OK, then Close. On a Mac use Formulas > Define Name. In Excel for the web the scope can only be Workbook.
Microsoft's advice is to test first: get the plain formula right, then test it inline with real cells, and only then save it as a name.
Examples
Test inline. Microsoft's simplest example. The (1) at the end passes 1 into number.
| A | |
|---|---|
| 1 | Result |
| 2 | 2 |
Microsoft's ToCelsius, one parameter. In Name Manager, the name TOCELSIUS refers to =LAMBDA(temp, (5/9) * (temp-32)). In the sheet you type only =TOCELSIUS(A2) and copy it down.
| A | B | |
|---|---|---|
| 1 | Fahrenheit | Celsius |
| 2 | 104 | 40 |
| 3 | 86 | 30 |
| 4 | 68 | 20 |
| 5 | 50 | 10 |
| 6 | 32 | 0 |
Microsoft's Hypotenuse, two parameters. HYPOTENUSE refers to =LAMBDA(a, b, SQRT((a^2+b^2))). You pass the inputs in the same order as the parameters, separated by a comma.
| A | B | C | |
|---|---|---|---|
| 1 | Side a | Side b | Hypotenuse |
| 2 | 3 | 4 | 5 |
| 3 | 5 | 12 | 13 |
| 4 | 7 | 24 | 25 |
| 5 | 9 | 40 | 41 |
Your own function: percent change. Year-over-year change is a formula people type all the time and often get backwards. Save it once as PCTCHANGE, referring to =LAMBDA(old, new, (new-old)/old), and nobody has to remember which value goes on the bottom.
| A | B | C | |
|---|---|---|---|
| 1 | Last year | This year | Change |
| 2 | $1,200 | $1,500 | 25.0% |
| 3 | $800 | $720 | -10.0% |
| 4 | $2,450 | $2,940 | 20.0% |
If you later decide the function should round its answer, edit the name's Refers to once and every cell that uses PCTCHANGE updates.
LAMBDA inside helper functions. A few newer functions take a LAMBDA as an argument and run it on each item of a range. MAP runs it on every value; BYROW runs it on each row. Here MAP converts the whole Fahrenheit column at once, without saving a name.
| A | B | |
|---|---|---|
| 1 | Fahrenheit | Celsius |
| 2 | 104 | 40 |
| 3 | 86 | 30 |
| 4 | 68 | 20 |
| 5 | 50 | 10 |
| 6 | 32 | 0 |
MAP and BYROW have the same availability as LAMBDA: Microsoft 365, Excel for the web and Excel 2024.
Common errors
#CALC!: the LAMBDA is in a cell but never called, as in=LAMBDA(x, x*2). Add the inputs,=LAMBDA(x, x*2)(5)returns 10, or save it as a name and call=DOUBLE(5).#VALUE!: you passed the wrong number of inputs, such as=HYPOTENUSE(3)when it needs two. The same error appears if a LAMBDA has more than 253 parameters.#NAME?: your Excel doesn't have LAMBDA (Excel 2021 and earlier), the function's name is misspelled, or the name was never saved in this workbook. Check Formulas > Name Manager: it should be listed there with your LAMBDA in Refers to.#NUM!: a LAMBDA that calls itself (recursion) went too deep, usually because it never reaches a point where it stops calling itself.- Excel won't accept the name or parameter: parameter names can't contain a period, and like LET names they can't look like a cell reference (
a1,c,r). - The wrong answer: test the calculation inline with known inputs. Microsoft notes that Evaluate Formula won't step inside a LAMBDA, so inline tests are the best check.
Related functions
- LET function: name the steps inside a formula; often used inside a LAMBDA's calculation.
- Excel formulas list: where LET and LAMBDA fit among the formulas in this course.
- Percentages: the percent-change formula behind PCTCHANGE.
- Excel errors and fixes: what every error value means.
Try it yourself
Download the practice workbook. You test LAMBDAs inline (the only way a checker can calculate them), work through Microsoft's ToCelsius and Hypotenuse examples and the percent-change function, then follow the steps to save TOCELSIUS in Name Manager and call it by name. An Answers sheet has every result.
Frequently asked questions
How do I create a custom function with LAMBDA?
Write and test the formula in a cell first, for example =LAMBDA(temp, (5/9)*(temp-32))(104), which returns 40. Then go to Formulas > Name Manager > New (on a Mac, Formulas > Define Name), type a name such as TOCELSIUS, paste the LAMBDA without the (104) into Refers to, and click OK. Now =TOCELSIUS(A2) works in any cell of that workbook.
Why does my LAMBDA show #CALC!?
You entered a LAMBDA in a cell without calling it. =LAMBDA(x, x*2) on its own has nothing to work on. Add the inputs in brackets right after it, =LAMBDA(x, x*2)(5) returns 10, or save the LAMBDA in Name Manager and call it by its name.
Is LAMBDA available in Excel 2021?
No. Microsoft lists LAMBDA for Excel for Microsoft 365 (Windows and Mac), Excel for the web, and Excel 2024 (Windows and Mac). Excel 2021 and earlier don't have it and show #NAME?.
Can I use a LAMBDA function in another workbook?
A named LAMBDA belongs to the workbook where you defined it. To use it in another file, define it there too: copy the Refers to formula from Name Manager and create the same name in the other workbook.
Is LAMBDA better than a VBA function?
For calculations, often yes. A LAMBDA is a normal formula, so it needs no VBA, no macros and no macro-enabled file, and it works in Excel for the web. VBA is still needed for things a formula can't do, such as changing formatting or working with other files.