Excel tutorial
/

Functions

Advanced

Excel LET function: using variables inside a formula

Use Excel LET to name parts of a long formula: calculate a repeated piece once and make formulas readable and fast. Syntax, examples, naming rules and traps.

Look at this bonus formula: =ЕСЛИ(B2/C2>=1,2;B2*7%;ЕСЛИ(B2/C2>=1;B2*5%;0)). B2/C2 (plan achievement) is written twice. A formula like this is hard to read and risky to edit: it’s easy to change one place and forget the other.

LET lets you declare a variable inside the formula: “share means B2/C2”. From then on the formula uses just the name. The result is the same, but the formula is shorter and clearer, and Excel calculates the repeated part once.

LET brings programming-style variables to Excel. It works in Excel 2021 and Microsoft 365.

Книга1 - Excel
—☐✕
D2fx882000
ABCDE
1ManagerSalesPlanBonus
2Aziz12 600 00010 000 000882 000
3Dilnoza9 500 0009 000 000475 000
4Javohir7 200 0008 000 0000
5Madina11 000 0009 000 000770 000
6
ГотовоСреднее: 531750Количество: 4Сумма: 2127000
The formula in D2: =LET(share,B2/C2,IF(share>=1.2,B2*7%,IF(share>=1,B2*5%,0))) — 120% of plan earns a 7% bonus, 100% earns 5%

Syntax

=LET(name1; value1; [name2; value2; ...]; calculation)

  • name1 — the variable name: share, price, vat.
  • value1 — its value: a number, cell, range or formula (B2/C2).
  • name2, value2, … — more pairs (up to 126). A later value can use earlier names.
  • calculation — the last argument: the formula that produces the result, using the names.

Naming rules: start with a letter, no spaces; must not look like a cell reference (a1, xy12 are not allowed); the single letters r and c are reserved too. A name exists only inside its own formula.

Turning a regular formula into LET

1

First write the formula as usual and check the result. Then find the part that repeats — here it’s B2/C2.

Книга1 - Excel
—☐✕
D2fx=ЕСЛИ(B2/C2>=1,2;B2*7%;ЕСЛИ(B2/C2>=1;B2*5%;0))
ABCDE
1ManagerSalesPlanBonus
2Aziz12 600 00010 000 000882 000
3Dilnoza9 500 0009 000 000475 000
4Javohir7 200 0008 000 0000
5
Готово
Without LET: B2/C2 appears twice in the formula bar

2

Start the formula with =LET( and name the repeated part: =LET(share;B2/C2; — name, comma, value, comma.

3

For the last argument, write the original formula but with share instead of B2/C2: IF(share>=1.2,B2*7%,IF(share>=1,B2*5%,0))). Press Enter — the result must match the old one.

4

Make a long LET readable: put each pair on its own line in the formula bar with Alt + Enter, and expand the formula bar with Ctrl + Shift + U.

Книга1 - Excel
—☐✕
D2fx14560000
ABCDE
1ProductPriceQtyWith VAT
2Fridge6 500 000214 560 000
3TV4 200 000314 112 000
4Vacuum cleaner1 800 000510 080 000
5
ГотовоСреднее: 12917333,3333Количество: 3Сумма: 38752000
Example 1: =LET(total,B2*C2,vat,total*12%,total+vat) — the second name (vat) uses the first (total)
Книга1 - Excel
—☐✕
F2fxApprove
ABCDEFG
1ClientRateYearsAmountSalaryDecision
2Aziz24%360 000 0006 000 000Approve
3Dilnoza22%240 000 0003 500 000Decline
4Javohir20%5100 000 0007 000 000Approve
5Madina18%120 000 0003 000 000Decline
6
ГотовоКоличество: 4
Example 2: =LET(pay,PMT(B2/12,C2*12,-D2),IF(pay>E2*50%,"Decline","Approve")) — if the payment exceeds half the salary, the loan is declined. Dilnoza: 2,075,126 > 1,750,000
Книга1 - Excel
—☐✕
F2fxCount: 3, average: 9,066,667
ABCDEFG
1ManagerSalesBranchBranch:Tashkent
2Aziz8 500 000TashkentResult:Count: 3, average: 9,066,667
3Dilnoza9 100 000Samarkand
4Javohir12 300 000Tashkent
5Madina4 200 000Samarkand
6Sardor6 400 000Tashkent
7Nodira7 800 000Bukhara
8
Готово
Example 3: =LET(s,FILTER(B2:B7,C2:C7=F1),"Count: "&COUNT(s)&", average: "&TEXT(AVERAGE(s),"#,##0")) — FILTER runs once, its result is used twice
Книга1 - Excel
—☐✕
D2fx#NAME?
ABCDE
1ManagerSalesPlanBonus
2Aziz12 600 00010 000 000#NAME?
3Dilnoza9 500 0009 000 000#NAME?
4Javohir7 200 0008 000 000#NAME?
5
ГотовоКоличество: 3
The same file in Excel 2019: LET isn’t recognized. Keep a non-LET version for those users

Pro level: speed, debugging and the road to LAMBDA

  • Speed. =ЕСЛИ(ISNA(ПРОСМОТРX(A2;Code;Price));0;ПРОСМОТРX(A2;Code;Price)*B2) runs the lookup twice. =LET(n;ПРОСМОТРX(A2;Code;Price);ЕСЛИ(ISNA(n);0;n*B2)) runs it once. On a 100,000-row table the difference is noticeable.
  • Step-by-step debugging. If the result is wrong, return an intermediate name instead of the last argument: =LET(share;B2/C2;share) shows whether share is calculated correctly. Then put the calculation back.
  • Settings in one place. =LET(rate;7%;threshold;1,2;ЕСЛИ(B2/C2>=threshold;B2*rate;0)) — the numbers sit at the start of the formula, with names. When the terms change, it’s obvious what to edit.
  • With dynamic arrays. =LET(d;ФИЛЬТР(A2:C100;C2:C100>0);СОРТ(d;3;-1)) — filter first, then sort; every step has a name.
  • Next step: LAMBDA. A LET formula can become your own function with LAMBDA and be called anywhere in the workbook through Диспетчер имён, like =BONUS(B2;C2) (Microsoft 365).

Try it in the simulator

The simulator doesn’t calculate LET, so write the equivalent without it: type =ЕСЛИ(B2/C2>=1,2;B2*7%;ЕСЛИ(B2/C2>=1;B2*5%;0)) in D2 and fill down to D5. Compare with the LET table above — the results must match (882,000, 475,000, 0, 770,000).

Книга1 - Excel
—☐✕
Буфер обмена
Шрифт
Выравнивание
Число
Стили
Ячейки
Редактирование
✕✓fx
ABCDEFGHIJKLMNOPQRSTUVWX
1ManagerSalesPlanBonus
2Aziz1260000010000000
3Dilnoza95000009000000
4Javohir72000008000000
5Madina110000009000000
6
7
8
9
10
Лист1
Готово

Has ExcelLab been useful?

Support the project and help us release new lessons and exercises.

Support us
Previous

140 / 154