LAMBDA · Financial
Margin LAMBDA
xl.margin returns profit as a share of the selling price. A $50 price on a $30 cost is a 40% margin.
Syntax =xl.margin(price, cost)
=LAMBDA(price, cost,
LET(
profit, price - cost,
IF(price=0, NA(), profit / price)
)
)Arguments
| Name | Required | What to pass |
|---|---|---|
| price | Required | The selling price. Zero returns #N/A. |
| cost | Required | The cost. Profit is price minus cost. |
Examples
A $50 item that cost $30
=xl.margin(50, 30)Result 40%
| A | B | |
|---|---|---|
| 1 | Price | 50 |
| 2 | Cost | 30 |
| 3 | Margin | 0.40 |
xl.margin divides profit by the price. Fifty dollars minus a thirty-dollar cost is twenty dollars, and twenty divided by fifty is 40%. Markup divides that same twenty by the cost and gets about 66.67%. The two words get swapped on quotes. This function is the price one.
A zero price is #N/A rather than a division error.
Add it to the workbook
Copy the formula in the block above, including the line breaks. Choose Formulas, Name Manager, New. Set the name to xl.margin, the scope to Workbook, and paste into Refers to. Excel Labs can do the same step: open the Advanced Formula Environment, add that name, and save it back to the workbook. A cell then calls =xl.margin(...).
The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME? for LAMBDA even when it already has XLOOKUP, FILTER, or LET.
How it works
Profit is price minus cost. The function divides by price after refusing a zero price. The result is a fraction. Format it as a percent.
Limits
It does not know overhead, tax, or shipping. A cost above the price is a negative margin, which is a real loss and is returned as a negative number. Markup is the other ratio, on its own page.