Skip to content

SWITCH

Compares one value with a list of options and returns the result for the first exact match, or a default if none match.

Syntax

=SWITCH(, , , [default_or_value2, result2], ...)

Logical

Excel for Microsoft 365, Excel 2024, Excel 2021, Excel 2019, Excel for the web and the mobile apps. Not available in Excel 2016 and earlier (perpetual versions), where it returns `#NAME?`.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
D
1
Order
Region code
Region
2
O-1
S
South
3
4

C2 =SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown") returns South

How SWITCH works

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.

Arguments

expression
The value to compare, usually a cell such as B2. It is evaluated once and compared with each value in turn.
value1
The first value to compare with the expression, such as "N" or 1. A match must be exact. Wildcards aren't supported.
result1
What to return if the expression equals value1. It can be text, a number, a reference or a formula.
default_or_value2, result2, ...optional
More value and result pairs, up to 126 pairs. If you add one final argument with no partner, it is the default result when nothing matches. With no default and no match, SWITCH returns #N/A.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Map codes to names, with a default

C2 =SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown")

Result: South

B2 is S, which matches the second pair. The last argument, "Unknown", has no partner, so it is the default for any other code.

C2
A
B
C
D
1
Order
Region code
Region
2
O-1
S
South
3
4

C2 =SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown") returns South

Example 2

No default: an unmatched code is #N/A

C2 =SWITCH(B2,"N","North","S","South","E","East","W","West")

Result: #N/A

X isn't in the list and there is no default, so SWITCH returns #N/A. Add a final result such as "Unknown" to handle it.

C2
A
B
C
D
1
Order
Region code
Region
2
O-2
X
#N/A
3
4

C2 =SWITCH(B2,"N","North","S","South","E","East","W","West") returns #N/A

Example 3

Numbers to labels

C2 =SWITCH(B2,1,"Low",2,"Medium",3,"High","Check")

Result: High

The expression is the number 3, which matches the third value. The numbers must be real numbers: text "3" wouldn't match.

C2
A
B
C
D
1
Ticket
Priority
Label
2
T-9
3
High
3
4

C2 =SWITCH(B2,1,"Low",2,"Medium",3,"High","Check") returns High

Example 4

SWITCH(TRUE, ...) for bands

C2 =SWITCH(TRUE,B2>=100,"Large",B2>=50,"Medium","Small")

Result: Medium

SWITCH compares TRUE with each condition in turn. 64 fails the first test and passes the second, so the result is Medium. The last argument, "Small", is the default.

C2
A
B
C
D
1
Order
Units
Size
2
O-3
64
Medium
3
4

C2 =SWITCH(TRUE,B2>=100,"Large",B2>=50,"Medium","Small") returns Medium

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In D2, turn the region code in column B into a name: N is North, S is South, E is East and W is West. Any other code should show Unknown. Fill down to D7.

Answer in D2, then it fills down to D7.

D2
A
B
C
D
E
1
Order
Region code
Units
Region
Size
2
O-01
X
30
3
O-02
E
120
4
O-03
W
64
5
O-04
S
100
6
O-05
N
49
7
O-06
E
50
8

Common mistakes

  • With no default argument, an unmatched value returns #N/A. Add a final result for "everything else".
  • Matching is exact, so a trailing space or a number stored as text won't match. "S " is not "S", and 3 is not "3".
  • SWITCH doesn't support wildcards or comparisons such as >=50 in the normal form. Use IFS, or the SWITCH(TRUE, ...) pattern.
  • SWITCH isn't available in Excel 2016 and earlier. There it returns #NAME?.
  • Long lists copied into many formulas are hard to maintain. Move the mapping to a table and look it up.

Questions people ask

How do I add a default to SWITCH?

Add one extra argument at the end, with no value in front of it. `=SWITCH(B2, "N", "North", "S", "South", "Unknown")` returns "Unknown" for any other code.

Why does SWITCH return #N/A?

Nothing matched and there is no default. Check the codes for stray spaces or number-versus-text differences, and add a default.

Can SWITCH test ranges, like greater than 50?

Not directly. Use `SWITCH(TRUE, B2>=50, "High", "Low")`, where each value is a condition, or use IFS.

What is the difference between SWITCH and CHOOSE?

SWITCH matches a value, such as a code, against a list you give. CHOOSE picks by position, so its first argument must be 1, 2, 3 and so on.

Learn SWITCH in a real sheet.

SWITCH is taught in Logic and text, lesson 4: SWITCH for code lookups. Each lesson is a short, graded exercise like the one above.