Going Stellar

Home/Google Sheets reference

Google Sheets function · Logical

LET in Google Sheets: syntax and examples

LET assigns names to values or formulas and then evaluates a final formula that uses those names. A long expression is written once and read by name, which makes big formulas shorter and easier to follow.

Syntax

LET(name1, value_expression1, [name2, …], [value_expression2, …], formula_expression )

Arguments

ArgumentTypeRequiredWhat it does
name1nameyesA name you choose, such as total. It cannot look like a cell reference.
value_expression1anyyesThe value or formula stored under name1. It is calculated once.
name2, value_expression2anynoMore name and value pairs. Later pairs can use earlier names.
formula_expressionanyyesThe last argument: the formula that uses the names and gives the result.

Examples

The examples use this table, starting in A1:

ItemQtyUnit
Lamp320
Chair250
Desk1120
=LET(x, 5, x*2)

Result: 10

Give a value a name and use it in the formula.

Run in a Google Sheet (English US locale) on .

=LET(q, B2, p, C2, q*p)

Result: 60

Two names, then a formula: quantity times unit value for one row.

Run in a Google Sheet (English US locale) on .

=LET(t, SUMPRODUCT(B2:B4, C2:C4), t - t/10)

Result: 252

The total is named once and used twice.

Run in a Google Sheet (English US locale) on .

=LET(r, C2:C4, MAX(r) - MIN(r))

Result: 100

A name can hold a whole range.

Run in a Google Sheet (English US locale) on .

=LET(s, "Hello", UPPER(s) & " " & LOWER(s))

Result: HELLO hello

Names work with text too.

Run in a Google Sheet (English US locale) on .

Common errors

  • The last argument must be the result formula. LET(x, 1) with no final expression returns #N/A.
  • A name cannot look like a cell reference. LET(A1, 5, A1) returns #NAME?.
  • Names exist only inside the LET call. Using x after the closing parenthesis returns #NAME?.
  • A name that was never defined in the pairs, used in the final formula, returns #NAME?.

Compared with Excel

Same syntax in Excel.

Sources

  1. LET (Docs Editors Help)

Markdown version · All functions