
The `SWITCH` function in Excel allows you to evaluate an expression against a list of values and return a result corresponding to the first matching value. It is particularly useful when you have multiple conditions to check against a single expression or value. The syntax of the `SWITCH` function is as follows:
SWITCH(expression, value1, result1, [value2, result2], ..., [default])
- `expression`: This is the expression or value that you want to compare to the list of values.
- `value1, value2, …`: These are the values that the `expression` is compared against.
- `result1, result2, …`: These are the results returned if the corresponding value matches the `expression`.
- `default` (optional): This is the result returned if none of the values match the `expression`. If you do not provide a `default` value and there is no match, `SWITCH` will return a `#N/A` error.
Example:
Assume you have a numerical grade in cell A1 and want to convert it to a letter grade. You can use the `SWITCH` function to do this:
=SWITCH(A1,
10, "A",
9, "B",
8, "C",
7, "D",
6, "E",
"F")
In this example:
- If `A1` is 10, it returns “A”.
- If `A1` is 9, it returns “B”.
- If `A1` is 8, it returns “C”.
- If `A1` is 7, it returns “D”.
- If `A1` is 6, it returns “E”.
- For any other value, it returns “F”.
Key Points:
- The `SWITCH` function can simplify formulas that would otherwise require long `IF` statements.
- Make sure that each `value-result` pair is properly aligned.
- If no default is specified, a non-matching value will result in an error.
- The `SWITCH` function is available in Excel 2016 and later versions, including Excel for Microsoft 365.
This function is best utilized when you have a fixed set of conditions to evaluate and is more readable than nested `IF` statements in such cases.