Excel tutorial
/

Functions

Intermediate

Excel SWITCH function: turn codes into names without an IF chain

SWITCH compares a value against a list of options and returns the matching result. Status codes, weekdays, the SWITCH(TRUE) trick and common traps.

SWITCH takes one value, compares it against a list of options and returns the result of the matching option. If nothing matches, it returns the “default” you provide.

The typical job is turning a code into a readable name: order status 1/2/3 → “New / In transit / Delivered”, a branch code → a city, a weekday number → its name. With IF it would be IF(B2=1,…,IF(B2=2,…,IF(…))), repeating B2 every time. In SWITCH the value is written once, followed only by pairs.

SWITCH is available in Excel 2019 and Microsoft 365.

Книга1 - Excel
—☐✕
C4fx=ПЕРЕКЛЮЧ(B4;1;"New";2;"In transit";3;"Delivered";"Unknown")
ABCD
1OrderCodeStatus
2#30011New
3#30023Delivered
4#30032In transit1
5#30045Unknown2
6#30053Delivered
7
Готово
1 — code 2 became “In transit”. 2 — code 5 is not in the list, so the default “Unknown” is returned

Syntax

=ПЕРЕКЛЮЧ(expression; value1; result1; [value2; result2]; ...; [default])

  • expression — the value to test: a cell (B2) or a formula (WEEKDAY(A2,2)).
  • value1, result1 — the first pair: if the expression equals value1, result1 is returned.
  • value2, result2 … — more pairs, up to 126.
  • default — an optional last argument without a pair: returned when nothing matches.

Excel counts the arguments: if one unpaired argument is left at the end, it is the default.

Step by step: entering a SWITCH formula

1

Select C2 for the result.

2

Формулы → Логические → pick SWITCH.

Книга1 - Excel
—☐✕
ФайлГлавнаяВставкаРазметка страницыФормулыДанныеРецензированиеВидСправка
Вставить функциюАвтосуммаФинансовыеЛогическиеТекстовыеДата и времяСсылки и массивыМатематические
Библиотека функций
Диспетчер имён
Определённые имена
C2fx
ABCD
1OrderCodeStatus
2#30011
3#30023
4
5
Готово

3

Type B2 in Expression. Then the pairs: Value1 — 1, Result1 — "New", Default_or_value2 — 2, Result2 — "In transit" and so on. In the last unpaired box type "Unknown".

Книга1 - Excel
—☐✕
C2fx
ABCD
1OrderCodeStatus
2#30011
3#30023
4
5
Готово

4

Click OK and fill the formula down. The finished version: =ПЕРЕКЛЮЧ(B2;1;"New";2;"In transit";3;"Delivered";"Unknown").

Example 1: workday or weekend from a date

WEEKDAY(A2,2) returns Monday as 1 and Sunday as 7. SWITCH tests that number: 6 and 7 are the weekend, everything else is a workday (the default).

=ПЕРЕКЛЮЧ(ДЕНЬНЕД(A2;2);6;"Weekend";7;"Weekend";"Workday")

Note that the expression can be a formula, and it is calculated only once.

Книга1 - Excel
—☐✕
C3fx=ПЕРЕКЛЮЧ(ДЕНЬНЕД(A3;2);6;"Weekend";7;"Weekend";"Workday")
ABCD
1DateDay numberDay type
201.01.20253Workday
304.01.20256Weekend
405.01.20257Weekend
506.01.20251Workday
6
Готово
04.01.2025 is a Saturday (6), 05.01.2025 a Sunday (7)

Example 2: SWITCH(TRUE, …) — working with ranges

SWITCH only tests equality. But there is a trick: use TRUE as the expression and conditions as the values. Excel looks for “which condition equals TRUE” and takes the first one:

=ПЕРЕКЛЮЧ(ИСТИНА;B2>=86;"Excellent";B2>=71;"Good";B2>=56;"Pass";"Fail")

It works like IFS, but unlike IFS it has a default at the end.

Книга1 - Excel
—☐✕
C3fx=ПЕРЕКЛЮЧ(ИСТИНА;B3>=86;"Excellent";B3>=71;"Good";B3>=56;"Pass";"Fail")
ABCD
1StudentScoreResult
2Aziz91Excellent
3Dilnoza74Good
4Javohir58Pass
5Kamola43Fail
6
Готово
The first condition that equals TRUE wins — that is why the highest threshold comes first

Pro level: calculate once, and when to switch to a table

  • A complex expression. The first two letters of a product code mark the branch: TS-104, SM-201. With IF, LEFT(A2,2) is repeated in every test; with SWITCH, once: =ПЕРЕКЛЮЧ(ЛЕВСИМВ(A2;2);"TS";"Tashkent";"SM";"Samarkand";"BX";"Bukhara";"Other").
  • A formula as the result. =ПЕРЕКЛЮЧ(C2;"Cash";B2;"Card";B2*0,99;B2) — a different calculation per payment type.
  • When to stop. With more than 6–8 options, or options that change often, move them into a separate lookup table and use XLOOKUP. Only someone who knows Excel can edit a list inside a formula; anyone can edit a table.
Книга1 - Excel
—☐✕
C3fx=ПЕРЕКЛЮЧ(ЛЕВСИМВ(A3;2);"TS";"Tashkent";"SM";"Samarkand";"BX";"Bukhara";"Other")
ABCD
1Product codeAmountBranch
2TS-1041 250 000Tashkent
3SM-201870 000Samarkand
4BX-033430 000Bukhara
5NM-310615 000Other
6
Готово
LEFT(A3,2) is calculated once and compared with “SM”

Try it in the simulator

Type =ПЕРЕКЛЮЧ(B2;1;"New";2;"In transit";3;"Delivered";"Unknown") in C2 and fill it down to C6. Then change the 5 in B5 to 2.

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

Has ExcelLab been useful?

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

Support us
Previous

84 / 154