How to Use SWITCH Function in Excel: Simple Guide
The
SWITCH function in Excel evaluates one value against a list of values and returns the result corresponding to the first match. It simplifies multiple IF statements by matching an expression to cases and returning a result or a default if no match is found.Syntax
The SWITCH function syntax is:
SWITCH(expression, value1, result1, [value2, result2], ..., [default])
expression: The value to compare.
value1, value2, ...: Values to match against the expression.
result1, result2, ...: Results returned if the corresponding value matches.
default (optional): Result if no match is found.
excel
SWITCH(expression, value1, result1, [value2, result2], ..., [default])Example
This example shows how to use SWITCH to assign a grade based on a letter:
If cell A1 contains a letter grade, the formula returns the full word grade.
excel
=SWITCH(A1, "A", "Excellent", "B", "Good", "C", "Average", "D", "Poor", "F", "Fail", "Invalid Grade")
Output
If A1 = "B", output is "Good"
Common Pitfalls
Common mistakes include:
- Not providing a default value, which returns
#N/Aif no match is found. - Forgetting to match data types exactly (e.g., text vs number).
- Using too many pairs, which can make the formula hard to read.
Example of wrong and right usage:
excel
Wrong: =SWITCH(A1, 1, "One", 2, "Two") // No default, returns #N/A if A1 is 3 Right: =SWITCH(A1, 1, "One", 2, "Two", "Other") // Returns "Other" if no match
Quick Reference
| Part | Description |
|---|---|
| expression | Value to compare |
| value1, value2, ... | Values to match against expression |
| result1, result2, ... | Results returned for each matching value |
| default (optional) | Result if no match is found |
Key Takeaways
Use SWITCH to simplify multiple IF statements by matching one expression to many values.
Always include a default result to avoid errors when no match is found.
Ensure the expression and values have matching data types for correct results.
SWITCH is easier to read and maintain than nested IFs for multiple conditions.