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.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Code | Status | |
| 2 | #3001 | 1 | New | |
| 3 | #3002 | 3 | Delivered | |
| 4 | #3003 | 2 | In transit1 | |
| 5 | #3004 | 5 | Unknown2 | |
| 6 | #3005 | 3 | Delivered | |
| 7 |
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,result1is 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.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Code | Status | |
| 2 | #3001 | 1 | ||
| 3 | #3002 | 3 | ||
| 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".
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Code | Status | |
| 2 | #3001 | 1 | ||
| 3 | #3002 | 3 | ||
| 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.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Date | Day number | Day type | |
| 2 | 01.01.2025 | 3 | Workday | |
| 3 | 04.01.2025 | 6 | Weekend | |
| 4 | 05.01.2025 | 7 | Weekend | |
| 5 | 06.01.2025 | 1 | Workday | |
| 6 |
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.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Student | Score | Result | |
| 2 | Aziz | 91 | Excellent | |
| 3 | Dilnoza | 74 | Good | |
| 4 | Javohir | 58 | Pass | |
| 5 | Kamola | 43 | Fail | |
| 6 |
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.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Product code | Amount | Branch | |
| 2 | TS-104 | 1 250 000 | Tashkent | |
| 3 | SM-201 | 870 000 | Samarkand | |
| 4 | BX-033 | 430 000 | Bukhara | |
| 5 | NM-310 | 615 000 | Other | |
| 6 |
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.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Order | Code | Status | |||||||||||||||||||||
| 2 | #3001 | 1 | ||||||||||||||||||||||
| 3 | #3002 | 3 | ||||||||||||||||||||||
| 4 | #3003 | 2 | ||||||||||||||||||||||
| 5 | #3004 | 5 | ||||||||||||||||||||||
| 6 | #3005 | 3 | ||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.