Back to Functions

LAMBDA

Creates and returns a custom function with a set of names and a formula_expression that uses them. To calculate the formula_expression, you can call the returned function with as many values as the name declares.

LogicalLAMBDA(name, formula_expression)

LAMBDA creates your own function from a formula. You choose the inputs, write the calculation once, and reuse it, either on the spot inside functions like MAP, or saved as a Named function that you can call from anywhere in the spreadsheet like SUM or VLOOKUP.

Syntax

=LAMBDA(name1, [name2, ...], formula_expression)
  • name1, name2, ...: The names of the inputs (parameters), which you choose.
  • formula_expression: The calculation, written using those names. It must be the last argument.

A LAMBDA on its own does nothing until it is called with values. Typing =LAMBDA(x, x * 2) returns an error. To test it, call it right away:

=LAMBDA(x, x * 2)(5)

Returns 10. The (5) after the LAMBDA passes the value 5 to x.

Why LAMBDA matters

  • Reuse. Write complex logic once and use it in many places, instead of copying long formulas.
  • Readability. A call like =NETPRICE(B2, C2) explains itself better than an unreadable expression.
  • Array processing. LAMBDA is the engine of MAP, REDUCE, SCAN, BYROW, BYCOL and MAKEARRAY, which apply your function over ranges.
  • Recursion. A Named function can call itself to solve repeating problems.

Using LAMBDA with MAP and friends

The most common use is to pass a LAMBDA to a helper function:

=MAP(A2:A10, LAMBDA(x, x * 2))

Doubles each value. x takes each item of A2:A10 in turn.

=MAP(A2:A10, B2:B10, LAMBDA(price, qty, price * qty))

Two arrays and a two-parameter LAMBDA: multiplies matching rows.

=REDUCE(0, A2:A10, LAMBDA(total, x, total + x))

REDUCE carries a running value (total) across the list. This one sums, but the same pattern can build text, find maximums with conditions, and more.

=SCAN(0, A2:A10, LAMBDA(total, x, total + x))

SCAN returns every running step: a running total column.

=BYROW(A2:C10, LAMBDA(row, SUM(row)))

Sums each row of a table. BYROW hands each whole row to the LAMBDA.

See MAP for more.

Creating a Named function

To reuse a LAMBDA anywhere in the file, save it as a Named function:

  1. Go to Data > Named functions > Add new function.
  2. Give it a name in capitals, such as NETPRICE.
  3. Add an optional description and example.
  4. List the argument placeholders, such as price, discount.
  5. Write the formula definition using those names, such as price * (1 - discount).
  6. Save.

Now =NETPRICE(B2, 0.1) works in any cell. Named functions can call other Named functions, and can be imported into other spreadsheets from the Named functions panel.

Note that in the Named functions dialog you write only the body of the formula (price * (1 - discount)), not LAMBDA(...) itself, because the dialog supplies the wrapper.

Practical patterns

A reusable cleaning function

A Named function CLEANTEXT with argument text and the definition:

PROPER(TRIM(SUBSTITUTE(text, CHAR(160), " ")))

Then =CLEANTEXT(A2) or =MAP(A2:A100, LAMBDA(t, CLEANTEXT(t))).

Per-row text joins

TEXTJOIN collapses a whole range, but with BYROW you can join each row separately:

=BYROW(A2:E10, LAMBDA(r, TEXTJOIN(", ", TRUE, r)))

Conditional logic per item

=MAP(A2:A10, LAMBDA(score, IFS(score >= 90, "A", score >= 80, "B", TRUE, "C")))

With LET inside

=MAP(A2:A10, LAMBDA(x, LET(y, TRIM(x), IF(y = "", "", UPPER(y)))))

Recursion

A Named function can call itself. A classic example is a factorial: FACT(n) defined as IF(n <= 1, 1, n * FACT(n - 1)). Keep an eye on the stopping condition so it doesn't loop forever.

Common errors

  • #ERROR! / "Lambda must be called". The LAMBDA was typed alone. Call it with (...) or pass it to MAP, REDUCE and similar.
  • "Wrong number of arguments". The call supplies a different number of values than the LAMBDA has parameters.
  • #NAME?. A parameter name is misspelled in the body, or you used the same name as a cell reference (A1).
  • Named function not found. The function must be saved under Data > Named functions before a formula can call it, and the name in the formula must match.
  • Circular dependency. The function references the cell that calls it.
  • Slow on huge ranges. MAP over whole columns processes blanks too. Use bounded ranges or filter blanks first.

LAMBDA vs. LET vs. Apps Script

  • LET names values inside a single formula.
  • LAMBDA creates a function you can reuse and pass around.
  • Apps Script custom functions can do more (for example call external services), but need code and permissions. For pure calculation, LAMBDA is simpler and runs faster.

Frequently asked questions

Do I need LAMBDA for MAP? Yes, MAP takes a LAMBDA (or a Named function) as its last argument.

Can I share Named functions? Yes: they are part of the spreadsheet and can be imported into other files.

How many parameters can a LAMBDA have? Several. Each parameter is a name before the final expression.

Related Functions

  • LET: Name values inside a formula.
  • MAP: Apply a function to each item of an array.
  • ARRAYFORMULA: Apply a formula to a whole range.
  • FILTER: Return the rows that meet a condition.
  • TEXTJOIN: Join text with a delimiter.

Related Articles

Newsletter

More LAMBDA examples coming soon.

We are building short, practical updates for Sheets power users.