The SWITCH formula in Excel is a powerful function that allows you to evaluate an expression against a list of values and return the corresponding result. It’s a more efficient and readable alternative to nested IF statements when dealing with multiple conditions. In this blog, we will learn how to use the SWITCH formula with examples using tables.
The basic syntax of the SWITCH function is:
=SWITCH(expression, value1, result1, [value2, result2], ..., [default_result])
Let’s say you have a table of student scores, and you want to categorize these scores into grades (A, B, C, etc.). You can use the SWITCH formula to achieve this.
Student Name | Score | Grade |
---|---|---|
John | 85 | =SWITCH(B2, 90, "A", 80, "B", 70, "C", "F") |
Mary | 92 | =SWITCH(B3, 90, "A", 80, "B", 70, "C", "F") |
David | 78 | =SWITCH(B4, 90, "A", 80, "B", 70, "C", "F") |
Sara | 65 | =SWITCH(B5, 90, "A", 80, "B", 70, "C", "F") |
In this case:
The formula in the Grade column evaluates the score and returns the respective grade.
Suppose you have numbers representing the days of the week (1 for Monday, 2 for Tuesday, etc.), and you want to convert these numbers into their corresponding day names.
Day Number | Day Name |
---|---|
1 | =SWITCH(A2, 1, "Monday", 2, "Tuesday", 3, "Wednesday", 4, "Thursday", 5, "Friday", 6, "Saturday", 7, "Sunday", "Invalid") |
3 | =SWITCH(A3, 1, "Monday", 2, "Tuesday", 3, "Wednesday", 4, "Thursday", 5, "Friday", 6, "Saturday", 7, "Sunday", "Invalid") |
5 | =SWITCH(A4, 1, "Monday", 2, "Tuesday", 3, "Wednesday", 4, "Thursday", 5, "Friday", 6, "Saturday", 7, "Sunday", "Invalid") |
8 | =SWITCH(A5, 1, "Monday", 2, "Tuesday", 3, "Wednesday", 4, "Thursday", 5, "Friday", 6, "Saturday", 7, "Sunday", "Invalid") |
Here, the SWITCH formula evaluates the number in the "Day Number" column and returns the respective day name. If the number does not match any valid day, the formula returns "Invalid."
The SWITCH formula in Excel is a valuable tool when you need to evaluate multiple conditions in a simple and efficient way. It makes your formulas easier to read and manage, especially when dealing with complex conditions. Give it a try in your next Excel project to streamline your calculations!
Feel free to experiment with the SWITCH formula and apply it to different situations in your Excel worksheets.