Skip to content

LAMBDA

Creates your own reusable function from parameters and a calculation. Save it with a name and call it like any other function.

Syntax

=LAMBDA([parameter1, parameter2, …], )

LAMBDA and LET

Excel for Microsoft 365, Excel 2024 and later, and Excel for the web. Not available in Excel 2021 or earlier.

Try it

Edit the formula in E2 or change the inputs. The sheet recalculates as you type.

E2
A
B
C
D
E
F
1
Item
Price
Qty
2
Gloves
8
12
96
3
Tape
3
40
4
Wrap
25
6
5
Labels
2
150
6
Bags
4
75
7

E2 =LAMBDA(price,qty,price*qty)(B2,C2) returns 96

How LAMBDA works

LAMBDA turns a calculation into a function of your own. You choose the inputs and the formula, give the whole thing a name, and from then on you can call it like SUM or XLOOKUP. No VBA is needed.

The arguments

All arguments except the last are parameters: the names you give to the inputs. The last argument is the calculation, which can use those names. =LAMBDA(price,qty,price*qty) is a function that multiplies two inputs.

Calling a LAMBDA

A LAMBDA does nothing until it is called. Typing =LAMBDA(price,qty,price*qty) into a cell returns #CALC!, because there is no input yet. To test it, put the inputs in brackets after the closing bracket:

=LAMBDA(price,qty,price*qty)(B2,C2)

Excel runs the calculation with price as B2 and qty as C2 and returns 96. This is the quickest way to try out a LAMBDA before you save it.

Saving it with a name

Once it works, make it reusable:

  1. On the Formulas tab, choose Name Manager, then New.
  2. Give it a name, such as NetPrice.
  3. In Refers to, enter the LAMBDA without the call: =LAMBDA(price,qty,price*qty).
  4. Click OK, then use it like any function: =NetPrice(B2,C2).

The name is available in every sheet of that workbook. If you change the definition, every cell that uses it updates. That is the point: your logic lives in one place. A named LAMBDA can also call itself, which allows recursion.

Optional parameters

Put a parameter in square brackets to make it optional, and test it with ISOMITTED: LAMBDA(x,[y],IF(ISOMITTED(y),x,x+y)). The function can then be called with one or two inputs.

LAMBDA with the helper functions

LAMBDA's partners do the looping. MAP runs a LAMBDA on every item, REDUCE accumulates a result, SCAN returns the running values, BYROW and BYCOL apply it to rows and columns, and MAKEARRAY builds a grid from it. You pass the LAMBDA as the last argument.

LET can store a LAMBDA for one formula: =LET(tax,LAMBDA(x,x*0.25),tax(B3)+tax(B4)).

Things to know

  • A named LAMBDA lives in the workbook. Copy it to another workbook by copying a sheet that uses it, or recreate it in the Name Manager.
  • A file that uses LAMBDA opens with #NAME? in versions that do not support it.
  • Parameter names can not look like cell addresses. qty is fine, q1 is not.
  • Give the name a clear description in the Name Manager comment box so others know what it does.

LAMBDA needs Microsoft 365, Excel 2024 or later, or Excel for the web.

Arguments

parameter1, parameter2, …optional
The names of the inputs, such as price, qty. A name can not look like a cell reference. Wrap a name in square brackets, such as [disc], to make it optional. You can have up to 253 parameters.
calculation
The formula that uses the parameters and produces the result. It is always the last argument.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Call a LAMBDA directly

E2 =LAMBDA(price,qty,price*qty)(B2,C2)

Result: 96

The brackets after the LAMBDA pass B2 as price and C2 as qty. 8 x 12 = 96.

E2
A
B
C
D
E
F
1
Item
Price
Qty
2
Gloves
8
12
96
3
Tape
3
40
4
Wrap
25
6
5
Labels
2
150
6
Bags
4
75
7

E2 =LAMBDA(price,qty,price*qty)(B2,C2) returns 96

Example 2

Average of a range, with one parameter

E2 =LAMBDA(r,SUM(r)/COUNT(r))(C2:C6)

Result: 56.6

The parameter r receives the whole range C2:C6. The quantities total 283 across 5 items, so the result is 56.6.

E2
A
B
C
D
E
F
1
Item
Price
Qty
2
Gloves
8
12
56.6
3
Tape
3
40
4
Wrap
25
6
5
Labels
2
150
6
Bags
4
75
7

E2 =LAMBDA(r,SUM(r)/COUNT(r))(C2:C6) returns 56.6

Example 3

Convert Celsius to Fahrenheit

C2 =LAMBDA(c,c*9/5+32)(A2)

Result: 68

One input, one calculation. Save it in the Name Manager as ToF and you can write =ToF(A2).

C2
A
B
C
D
E
F
1
Celsius
2
20
68
3
4

C2 =LAMBDA(c,c*9/5+32)(A2) returns 68

Example 4

Store a LAMBDA with LET and call it twice

C2 =LET(tax,LAMBDA(x,x*0.25),tax(A2)+tax(A3))

Result: 40

LET gives the LAMBDA the name tax for this one formula. It is called for 100 and for 60: 25 + 15.

C2
A
B
C
D
E
F
1
Sale
2
100
40
3
60
4

C2 =LET(tax,LAMBDA(x,x*0.25),tax(A2)+tax(A3)) returns 40

Example 5

A LAMBDA with no call returns #CALC!

C2 =LAMBDA(x,x*0.25)

Result: #CALC!

Excel has nothing to run until you supply an input. Add (A2) at the end and the formula returns 25.

C2
A
B
C
D
E
F
1
Sale
2
100
#CALC!
3
4

C2 =LAMBDA(x,x*0.25) returns #CALC!

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In C2, write a LAMBDA with two parameters that multiplies them, and call it with the quantity in A2 and the price in B2.

Answer in C2.

C2
A
B
C
D
E
F
1
Qty
Unit price
Line total
2
12
8
3
4
Celsius
Fahrenheit
5
20
6
7
8
9
10

Common mistakes

  • A LAMBDA typed into a cell without inputs returns #CALC!. That is expected. Test it by adding the inputs in brackets at the end, such as (B2,C2).
  • In the Name Manager, "Refers to" must be the LAMBDA only, with no inputs. If you paste a formula that includes (B2,C2), the name returns one fixed result.
  • #NAME? after typing a saved function means the name is misspelled, or the file is open in a version of Excel without LAMBDA. Check the name in the Name Manager.
  • Parameter names that look like cell references, such as q1 or tax1, are not allowed. Use names like qty or tax_rate.
  • A function that works on one value does not automatically work on a range. Pass it to MAP to run it on each item.

Questions people ask

How do I create a custom function in Excel without VBA?

Write a LAMBDA, then save it in the Name Manager: Formulas > Name Manager > New, give it a name and put the LAMBDA in Refers to. Then call it like any function: `=NetPrice(B2,C2)`.

Why does my LAMBDA return #CALC!?

It has no inputs yet, so there is nothing to calculate. Call it with brackets and values, such as `=LAMBDA(x,x*2)(5)`, or use it through a name or a helper function like MAP.

What is the difference between LET and LAMBDA?

LET names values inside one formula. LAMBDA defines a function with inputs that you can reuse, in one formula, or across the workbook once you give it a name.

Can a LAMBDA call itself?

Yes, when it is saved as a named function. The name can appear inside its own definition, which lets you write recursive calculations. Always include a condition that stops the recursion.

Does LAMBDA work in older versions of Excel?

No. It is available in Microsoft 365, Excel 2024 and later, and Excel for the web. In earlier versions a workbook that uses it shows `#NAME?`.

Learn LAMBDA in a real sheet.

LAMBDA is taught in Dates and financial modelling, lesson 22: Reusable calculations with LAMBDA. Each lesson is a short, graded exercise like the one above.