SWITCH compares one value against a list of possibilities and returns the result for the first one that matches. =SWITCH(B2, "N", "North", "S", "South", "E", "East", "W", "West", "Unknown") turns a one-letter region code into a name, and returns "Unknown" for anything else.
The arguments
- expression is the value to test. It is calculated once.
- value1, result1, value2, result2, ... are pairs. If the expression equals value1, SWITCH returns result1. Otherwise it tries the next pair.
- default is an optional last argument, with no partner. It is returned when nothing matches. Without it, SWITCH returns
#N/A.
Matches are exact, and there are no wildcards. The number 1 doesn't match the text "1".
SWITCH, IFS, CHOOSE and lookups
- Use SWITCH when you compare one value with exact options. It reads cleaner than a nest of IFs that repeat
B2= each time. - Use IFS when the tests differ, such as ranges and comparisons.
- Use CHOOSE when the input is already a position (1, 2, 3) rather than a label.
- Use a lookup table read with XLOOKUP when the list is long, used in several places or likely to change. Then the options live in cells, not in a formula.
The SWITCH(TRUE, ...) pattern
You can pass TRUE as the expression and conditions as the values: =SWITCH(TRUE, C2>=100, "Large", C2>=50, "Medium", "Small"). SWITCH tests each condition against TRUE in turn and returns the first one that is TRUE. It behaves like IFS with a built-in default, and some people find it easier to read. The order matters: put the strictest test first.
Errors and edge cases
- With no default, an unmatched expression returns
#N/A. Add a default, even a simple "Other". - If the expression is an error, SWITCH returns that error.
- If a result is an error but isn't chosen, nothing happens: SWITCH returns only the chosen result.
- Arguments must be in pairs, apart from the optional default.
Compatibility
SWITCH was added in Excel 2019. In Excel 2016 and earlier it returns #NAME?. If the file may open there, use nested IF or a lookup table.
Keep lists short
Ten or fewer pairs is comfortable. Longer lists make a formula hard to review, and the same mapping repeated in many formulas is a maintenance risk. If you copy a SWITCH to ten sheets and then need to add a region, you will edit it ten times. A table of codes and names, read with XLOOKUP, avoids that.