Make your own function with LAMBDA
LET and LAMBDA8 minPremium
Builds on Name the steps of a formula with LET.
A finance team in Toronto works out gross margin the same way in a dozen reports, and every copy of the formula is a chance for a typo. With LAMBDA they write the calculation once, give it a name, and type Margin( wherever they need it.
How it works
LAMBDA( describes a calculation with placeholders, its parameters, which stand for the values it gets later. Typed into a cell on its own, it shows #CALC!, because nothing has given it those values yet.
To use it, give it a name: on the Formulas tab, select Name Manager, then New, type a name such as Margin, paste the LAMBDA into Refers to, and select OK. From then on the name works like a built-in function in any cell of that workbook. The values in a call go to the parameters in order: in the example below, Margin( makes B2 the price and C2 the cost.
Think of it as a recipe card: it lists what goes in, and each call brings its own. Change the card in Name Manager and every cell that uses it follows.
Test it on real cells before you name it. LET can give a LAMBDA a name for one formula: =LET(.
Example
A margin is the share of the price left after the cost.
=LAMBDA(price,cost,(price-cost)/price)Saved in Name Manager as Margin, it gives 35% for a price of $80.00 in B2 and a cost of $52.00 in C2.
| Parameter | In Margin(B2, | Value | |
|---|---|---|---|
| 1 | price | B2 | $80.00 |
| 2 | cost | C2 | $52.00 |
| 3 | Result | (price-cost)/price | 35% |
- Step 1: B2, the first value in the call, goes to the first parameter, price.
- Step 2: C2 goes to the second parameter, cost.
- Step 3: The calculation runs with them, and $28 out of $80 is 35%.
Common mistakes
Margin(gives one value to a function that takes two, and showsB2) #VALUE!. Give every parameter a value.Margin(swaps the values, so the cost is read as the price. Give them in the order of the parameters.C2, B2) - A name lives in the workbook where you made it. To use it in another one, copy a sheet that uses it into that workbook, and Excel brings the name along.
In short
- A LAMBDA describes a calculation, and a name in Name Manager turns it into a function.
- Call it like a built-in function, with the values in the order of its parameters.
- Test it first inside LET, on real cells.
- The name works in any cell of its workbook.
Practice
Premium4 exercises: 2 formulas, 1 set of steps and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in