What SWITCH does
SWITCH compares one value with a list of values and returns the result paired with the first one that matches. =SWITCH(B2,"P","Paid","O","Open","C","Cancelled","Check code") turns the one-letter status codes of a system export into words, and shows Check code for anything it doesn’t know.
It does the work of a chain of IFs that all test the same cell, such as IF(B2="P",…,IF(B2="O",…)). The value to check goes in once, at the start, followed by pairs of a value and its result. A final argument without a partner is the default.
The matches are exact, which suits codes and the results of functions such as WEEKDAY. For comparisons such as “70 or more”, use IFS.
Syntax
expressionRequired- The value to look up, usually a cell such as
B2, or a calculation likeWEEKDAY(A2). value1Required- The first value to compare it with, such as the code
"P". The match must be exact. result1Required- What to return when the expression equals
value1, such as"Paid". default_or_value2Optional, can repeat- Another value to compare with, followed by its result. Add pairs up to 126. A last argument on its own, with no result after it, is the default, returned when nothing matches.
result2Optional, can repeat- What to return when the expression equals the value before it.
Example: status names from a system’s codes
An order export marks each order’s status with a letter. The formula in C2 is filled down to C5.
Read it as: if B2 is P, show Paid; if it’s O, show Open; if it’s C, show Cancelled; otherwise show Check code. Without the default, row 5 would show #N/A, which is easy to miss in a long export.
Example: a pay rate from the day of the week
The value SWITCH checks can be a calculation. A café pays a weekend rate, and WEEKDAY gives 1 for Sunday and 7 for Saturday.
WEEKDAY runs once per row, and SWITCH compares its answer with 1 and 7. Every other day falls through to Standard.
SWITCH vs IFS and nested IF
All three can choose between several results. The difference is what they test:
- SWITCH compares one value with a list of exact values. It’s the shortest way to turn codes into names.
- IFS runs a separate test for each result, so it handles bands such as
B2>=70and tests on different cells. - A nested IF does either job and works in every version of Excel. SWITCH and IFS need Microsoft 365 or Excel 2019 or later.
When the codes are 1, 2, 3 and so on, CHOOSE is shorter again: =CHOOSE(B2,"Low","Medium","High") picks the second word when B2 is 2.
Common mistakes
=SWITCH(B2,">=80","High","Other")looks for the text >=80 and never finds it, because SWITCH only compares for an exact match. Use IFS for comparisons.- Without a default, a value that matches nothing shows
#N/A. Add one last argument with no result after it, such as"Check code". - A code stored as text doesn’t match a number. If B2 holds the text “1”,
=SWITCH(B2,1,"Low","No match")shows No match. Convert the column, or compare with"1"in quotation marks. - The default has to be the last argument. Put a pair after it and Excel reads the default as one more value to match.
Frequently asked questions
What is the difference between SWITCH and IFS?
SWITCH compares one value with a list of exact matches, which suits codes. IFS runs a separate test for each result, so it handles comparisons such as greater than and tests on different cells.
Can SWITCH use greater than or less than?
Not as a value to match: ">=80" is read as text. Use IFS for comparisons. You’ll also see =SWITCH(TRUE,B2>=90,"A",B2>=80,"B","C"), which works because each test gives TRUE or FALSE and SWITCH returns the result of the first TRUE one, but IFS says the same more plainly.
What does SWITCH return when nothing matches?
The default, if you gave one as the last argument. Without a default, it shows #N/A.
How many values can SWITCH check?
Up to 126 pairs of a value and its result, plus the default.
Which versions of Excel have SWITCH?
Microsoft 365, Excel for the web, and Excel 2019 or later. In Excel 2016 the formula shows #NAME?; use nested IFs there, or CHOOSE when the codes are 1, 2, 3.