What is the SWITCH function?
=SWITCH(expression, value1, result1, [value2, result2], ..., [default])SWITCH compares one value with a list of values in order and returns the result for the first one that matches. For pairing exact values, like turning grade codes into grade names, it is simpler than nesting IFs.
According to Microsoft, if nothing matches and there is no default, you get #N/A. Check it with grade D in the sheet above.
Arguments
- expression
- The value or cell to compare.
- value1, result1, ...
- Pairs of a value to compare and the result to return for it.
- default
- Optional. The value returned when nothing matches; put just one at the very end.
SWITCH examples
Example 1. Grade names
=SWITCH(B2, "A", "Excellent", "B", "Average", "C", "Needs work", "Check")If B2 is "A", the result is "Excellent".
Example 2. Example from Microsoft
=SWITCH(A6, 1, "Sunday", 2, "Monday", 3, "Tuesday", "No match")If A6 is 3, the result is "Tuesday".
Common mistakes
Comparing greater or less
SWITCH only checks for equality. Use IFS to split into ranges.
Older versions
It is available in Excel 2019 and later and Microsoft 365.
FAQ
- How is it different from IFS?
- IFS tests conditions; SWITCH checks whether one value equals each item.
- What if the default is left out?
- You get #N/A when nothing matches.