Tabellab
Excel formulas

LAMBDA function in Excel: how to create your own custom functions

The LAMBDA function lets you build your own Excel function from an ordinary formula, without VBA or macros. You list the parameters, then the calculation: =LAMBDA(price,cost,(price-cost)/price) describes a margin function. Test it in a cell by adding the arguments in brackets, =LAMBDA(price,cost,(price-cost)/price)(C2,B2), then save it under a name such as MarginPct and use it like any built-in function. In the worked example six products have an average margin of 47.7%, and 2 of them fall below a 40% threshold.

Updated 21 Oct 2026 5 min read By Tabellab team

The LAMBDA syntax

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

  • Parameters are placeholder names for the values you pass in, up to 253 of them. Use clear names such as price or rate, not cell addresses.
  • The calculation is the last argument and uses the parameter names like cells.
  • Typed into a cell on its own, a LAMBDA only describes a function, so Excel shows #CALC!. It calculates when you call it with arguments.

LAMBDA is available in Microsoft 365, Excel 2024 and Excel for the web. It is not in Excel 2021 or older.

Step 1: write and test it inline

Call a LAMBDA directly in a cell by putting the arguments in brackets right after it. In D2 of the example, =LAMBDA(price,cost,(price-cost)/price)(C2,B2) passes the price 39.00 as price and the cost 18.40 as cost and returns a margin of 52.8%. The arguments are matched by position, so the order matters: (B2,C2) would calculate a nonsense margin of −112%. Fill the formula down and check a few rows by hand before you go further. That is the whole point of testing inline: a mistake is still easy to see.

Step 2: save it as a named function

When the inline version is right, turn it into a workbook function:

  1. Go to Formulas → Name Manager → New.
  2. Name: MarginPct. Add a comment that describes the parameters, it appears as a tooltip.
  3. Refers to: =LAMBDA(price,cost,(price-cost)/price), without the arguments.

From then on =MarginPct(C2,B2) works in every sheet of the workbook, and Excel suggests it as you type. The tax column works the same way: =LAMBDA(price,rate,ROUND(price*(1+rate),2)) saved as TaxPrice turns the desk lamp's 39.00 into 42.12 at an illustrative 8% rate. Change the rule once in the Name Manager and every formula that uses it updates.

Worked example: margin and tax functions for six products

Columns D and E call two LAMBDAs inline, exactly the way you test them before saving them as MarginPct and TaxPrice. Rows 13 to 19 use LAMBDA inside LET, MAP, REDUCE and SCAN.

Worked example: margin and tax functions for six products
ABCDE
1ProductCostPriceMargin %Price incl. tax
2Desk lamp18.4039.0052.8%42.12
3Oak shelf52.0089.0041.6%96.12
4Wool throw27.5064.0057.0%69.12
5Side table61.0098.0037.8%105.84
6Ceramic vase9.8024.0059.2%25.92
7Floor rug74.00119.0037.8%128.52
8
9Sales tax rate (illustrative)8%
10Margin threshold40%
11
12LAMBDA with LET and the helper functionsResult
13LET: a local Margin function, used for the floor rug37.8%
14Nested: 15% off the wool throw, then tax (two LET functions)58.75
15MAP: average margin of all six products47.7%
16MAP: products below the margin threshold2
17REDUCE: total of all prices incl. tax467.64
18Check: REDUCE total minus SUM of column E0.00
19SCAN: running total of prices after the 3rd product192.00
Key formulas
  • D2=LAMBDA(price,cost,(price-cost)/price)(C2,B2)Inline test of MarginPct
  • E2=LAMBDA(price,rate,ROUND(price*(1+rate),2))(C2,$E$9)Inline test of TaxPrice
  • E15=AVERAGE(MAP(C2:C7,B2:B7,LAMBDA(price,cost,(price-cost)/price)))MAP over two ranges
  • E17=REDUCE(0,C2:C7,LAMBDA(total,price,total+ROUND(price*(1+E9),2)))REDUCE to one total

Fictional products, illustrative tax rate. Once saved in the Name Manager, D2 becomes =MarginPct(C2,B2) and E2 becomes =TaxPrice(C2,$E$9), with the same results.

LAMBDA inside LET: functions for one formula

If you need a function only inside one long formula, store it in a LET variable instead of the Name Manager: =LET(Margin,LAMBDA(price,cost,(price-cost)/price),Margin(C7,B7)) returns 37.8% for the floor rug. Several LET functions can be nested: 15% off the wool throw's 64.00 with SalePrice, then tax with WithTax, gives 58.75. Avoid variable names that are also Excel function names (DISC, for example, is a built-in function).

MAP, REDUCE, SCAN and BYROW

LAMBDA is also the engine of the helper functions that loop over a range for you:

  • MAP(range, LAMBDA(x, …)) applies the function to every element: the average of the six margins is 47.7%, and counting those below the threshold in E10 gives 2 (the side table and the floor rug).
  • REDUCE(start, range, LAMBDA(total, x, …)) carries one value through the range and returns the final result: the sum of all prices including tax, 467.64.
  • SCAN works like REDUCE but returns every step, a running total. BYROW and BYCOL apply a function to each row or column.

If margin and markup are easy to confuse, see the guide on markup vs margin: a markup function would divide by the cost instead.

LAMBDA or a VBA function?

A named LAMBDA lives in the workbook like any other name: no macros, no security warning, the file stays an .xlsx and it works in Excel for the web. A VBA user-defined function can do things a formula cannot, such as reading files or calling other programs, but needs a macro-enabled file. For calculations, LAMBDA is usually the better choice. One limit: a named LAMBDA is only available in the workbook where it was defined, so copy a sheet that uses it into the new workbook or add the name there.

Common mistakes

  • Forgetting to call the LAMBDA. =LAMBDA(x,x*2) alone returns #CALC!. Add the arguments, =LAMBDA(x,x*2)(A2), or save it as a name.
  • The wrong number of arguments. A LAMBDA with two parameters called with one or three arguments returns #VALUE!.
  • Arguments in the wrong order. They are matched by position, not by name. MarginPct(B2,C2) swaps price and cost without any error message.
  • Parameter names that Excel cannot use. Names that look like cell addresses (TAX1) and the single letters r and c are not allowed. Use descriptive names.
  • Including the arguments in the Name Manager. "Refers to" must contain only the LAMBDA, not the (C2,B2) you used for the test.
  • Skipping the inline test. A named function hides its formula, so a mistake spreads to every cell that uses it. Test on a few rows first.

Frequently asked questions

What does the LAMBDA function do in Excel?

LAMBDA turns a formula into a reusable function with its own parameters. Saved under a name in the Name Manager, it can be used in any cell of the workbook like a built-in function, without VBA.

Why does my LAMBDA return #CALC!?

A LAMBDA on its own only defines a function. Excel needs arguments to calculate a result, so either call it inline, for example =LAMBDA(x,x*2)(A2), or save it in the Name Manager and call it by its name.

Which Excel versions have LAMBDA?

LAMBDA is available in Microsoft 365, Excel 2024 and Excel for the web. It is not available in Excel 2021, 2019 or older versions.

Can I use a LAMBDA in another workbook?

Not automatically. A named LAMBDA belongs to the workbook where it was defined. Copy a sheet that uses it into the other workbook, or create the same name there.

Practise it in a lab

Related guides

Reading is step one. Doing is step two.

Every guide links to a lab where you build the same calculation in an online spreadsheet and get instant feedback.

Open the lab