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.

Microsoft 365, Excel 2024, and Excel for the web. Excel 2021 does not have LAMBDA.

Syntax =xl.margin(price, cost)

xl.margin
=LAMBDA(price, cost,
  LET(
    profit, price - cost,
    IF(price=0, NA(), profit / price)
  )
)

Arguments

NameRequiredWhat to pass
priceRequiredThe selling price. Zero returns #N/A.
costRequiredThe cost. Profit is price minus cost.

Examples

A $50 item that cost $30

=xl.margin(50, 30)

Result 40%

=(B1-B2)/B1B3
Margin
AB
1Price50
2Cost30
3Margin0.40
A picture of the sheet, not a live calculator.

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.