Excel function

SWITCHfunction

Compares a value with a list in order and returns the result for the first match.

Excel 2019+
=SWITCH(B2, "A", "Excellent", "B", "Average", "C", "Needs work", "Check")
A
B
C
1
2
3
4
5
6

Click a cell in the table to change expression. Clear the default and the row with grade D shows #N/A. Try breaking it on purpose to see the errors.

Result

Excellent

expression
B2You can also click a cell in the table

The cell to compare with the list. Click another person's grade in the sheet.

value1

The first value to compare.

result1

The result returned when it equals value1.

value2

The second value to compare.

result2

The result returned when it equals value2.

value3

The third value to compare.

result3

The result returned when it equals value3.

default

The value returned when nothing matches. Leave it empty to omit it, which gives #N/A.

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

  1. Example 1. Grade names

    =SWITCH(B2, "A", "Excellent", "B", "Average", "C", "Needs work", "Check")

    If B2 is "A", the result is "Excellent".

  2. 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

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.