Level 3LET and LAMBDAReading, 5 min

LAMBDA and MAP: your own logic on every row

LAMBDA lets you write a formula with named inputs: LAMBDA(spend, rev, rev/spend). On its own it does nothing. It's a recipe waiting for ingredients.

The helper functions supply them:

  • MAP(range1, range2, LAMBDA(a, b, ...)) runs your recipe once per cell, pairing up values from each range, and spills the results.
  • BYROW(range, LAMBDA(row, ...)) hands over a whole row at a time. MAX(row) gives each row's best value.
  • BYCOL does the same per column. SCAN builds running totals and REDUCE boils a list down to one value. More on those later in this section.

Why bother, when ARRAYFORMULA exists? Readability and control. =MAP(B2:B6, C2:C6, LAMBDA(spend, rev, IF(spend=0, 0, rev/spend))) reads like the rule it implements, and IF inside a LAMBDA works on one value at a time, so there's no AND gotcha.

Go further with Data › Named functions: save a LAMBDA as ROAS(spend, rev) and anyone on the sheet can call it like a built-in function. That's how teams turn their house rules into formulas nobody has to rewrite.