How to Use the LET Function in Google Sheets | Define Variables Inside Formulas for Better Readability
What Is the LET Function?
The LET function lets you assign names (variables) to calculation results or cell ranges within a single formula, and then use those names to build the final expression. Because you no longer need to repeat the same calculation multiple times, your formulas become much easier to read and recalculation performance improves.
Syntax
=LET(name1, value_expression1, [name2, value_expression2, ...], formula_expression)
- name1: The name of the first variable (e.g.,
total,rate). - value_expression1: The value, cell reference, or formula assigned to
name1. - name2, value_expression2, …: [Optional] Additional variable name and value pairs as needed.
- formula_expression: The formula that uses the defined variables to output the final result (always the last argument).
Example
Here is an example of assigning the average sales of A2:A6 to a variable named avg and checking whether each row’s sales in Column A is "Above Average" or "Below Average" (avoiding having to write AVERAGE($A$2:$A$6) twice).
| Row | Column A (Sales) | Formula in Column B | Column B (Evaluation) |
|---|---|---|---|
| 1 | Sales | Evaluation | Evaluation |
| 2 | 120 | =LET(avg, AVERAGE($A$2:$A$6), IF(A2>=avg, "Above Average", "Below Average")) |
Above Average |
| 3 | 80 | =LET(avg, AVERAGE($A$2:$A$6), IF(A3>=avg, "Above Average", "Below Average")) |
Below Average |
| 4 | 100 | =LET(avg, AVERAGE($A$2:$A$6), IF(A4>=avg, "Above Average", "Below Average")) |
Above Average |
| 5 | 90 | =LET(avg, AVERAGE($A$2:$A$6), IF(A5>=avg, "Above Average", "Below Average")) |
Below Average |
| 6 | 110 | =LET(avg, AVERAGE($A$2:$A$6), IF(A6>=avg, "Above Average", "Below Average")) |
Above Average |
Common Errors and Notes
#ERROR!(Even Number of Arguments): BecauseLETconsists of “name-and-value pairs (even number)” plus “the finalformula_expression(1 argument)”, the total number of arguments must always be an odd number of 3 or more. Forgetting the finalformula_expressiontriggers an error.- Variable Naming Rules: Names that look like cell references (such as
A1orB2) or conflict with existing function names will cause errors. Use clear names liketarget_sumortax_price. - Scope Is Limited to the Same Cell: Variables defined in
LETare only valid within the formula in that specific cell. You cannot reference those variable names from other cells.
Frequently Asked Questions
Q. Why does using the LET function speed up calculations?
A. Instead of writing the same heavy calculation (like VLOOKUP or FILTER) multiple times inside a formula, you can assign it to a variable once and reuse it, reducing the number of calculations Google Sheets has to perform.
Q. Can I define multiple variables inside a LET function?
A. Yes. You can define as many "name, value" pairs as you like—such as =LET(a, 10, b, 20, a + b)—and you can even reference earlier variables when defining later ones.