This function assigns a name with the value_expression results and returns the result of the formula_expression.

Sample Usage

LET(avg, AVERAGE(B2:D2), IF(avg>=4, "Great", IF(avg>=3, "Good", "Poor"))): Categorize an average value.

LET(criteria, "Fred", range, FILTER(A2:D8, A2:A8=criteria), ARRAYFORMULA(IF(ISBLANK(range), "-", range))): Filter data and replace blank cell with dash.

Syntax

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

  • name1: A name used inside the next value_expressions and the formula_expression. This must be an identifier (details below), and usage is case-insensitive.
  • value_expression1: Formula whose result can be referred to later with the name that was declared before. It can use names declared in the previous parameters.
    • For example, AVERAGE(B2:D2).
  • name2…: [ OPTIONAL ] Repeatable, additional names to be assigned.
  • value_expression2…: [ OPTIONAL ] Repeatable, additional value_expressions to be evaluated.
  • formula_expression: Formula to be calculated. It uses names declared in the LET function.

Tip: You can use formula_expression as the names defined in the scope of the LET function. The value_expressions evaluates only once in the LET function, even if the next value_expressions or the formula_expression uses them multiple times.

Examples

Categorize the average value of product ratings with LET

Example Data:

1ProductJanuary ratingsFebruary ratingsMarch ratings
2Red t-shirt3.543
3Black jeans4.553.5
4Hat32.52

With LET: Input this formula in E2 and drag the blue box around the cell down to fill E3 and E4.

=LET(avg, AVERAGE(B2:D2), IF(avg>=4, "Great", IF(avg>=3, "Good", "Poor")))

Without LET: Input this formula in E2 and drag the blue box around the cell down to fill E3 and E4.

=IF(AVERAGE(B2:D2)>=4, "Great", IF(AVERAGE(B2:D2)>=3, "Good", "Poor"))

Result:

1ProductJanuary ratingsFebruary ratingsMarch ratingsAverage Rating Category
2Red t-shirt3.543Good
3Black jeans4.553.5Great
4Hat32.52Poor

Make a Copy

Filter data & replace blank cell with dash using LET

Return all data for “Fred” and replace blank cells with dash.

Example Data:

1RepRegionProductProfit
2AmyEastApple$1.33
3FredSouthBanana$0.09
4AmyWestMango$1.85
5FredNorth$0.82
6FredWestBanana$1.25
7AmyEastApple$0.72
8FredNorthMango$0.54

With LET: Input this formula in E2:

=LET(criteria, "Fred", range, FILTER(A2:D8, A2:A8=criteria), ARRAYFORMULA(IF(ISBLANK(range), "-", range)))

Without LET: Input this formula in E2:

=ARRAYFORMULA(IF(ISBLANK(FILTER(A2:D8, A2:A8="Fred")), "-", FILTER(A2:D8, A2:A8="Fred")))

Result:

1RepRegionProductProfit
2FredSouthBanana0.09
3FredNorth-0.82
4FredWestBanana1.25
5FredNorthMango0.54

Make a Copy

Common Errors

The name argument isn’t an identifier

Example: =LET(B2, AVERAGE(B2:D2), IF(B2>=4, "Great", IF(B2>=3, "Good", "Poor")))

If the argument isn’t an identifier, this error occurs:

Identifier requirements:

  • Can’t be ranges, like “A1” or “A2”
  • Can’t have spaces or special characters
  • Can’t start with numbers, like “9hello”

Left-to-right scoping problem

In a value_expression inside the LET function, this syntax lets you use the named arguments which have already been declared earlier. For example, “left in the function.”

Example:

LET(x, 1, y, LET(z, 2, x+z), x+y)CORRECT — x has been declared before using it in the inner LET function.
LET(y, LET(z, 2, x+y), x, 1, x+y)WRONG — using x before its declaration.

If you use an argument before it’s declared, this error occurs: