How to use Switch Formula in Excel

How to Use the SWITCH Formula in Excel

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.

Syntax of the SWITCH Formula

The basic syntax of the SWITCH function is:

=SWITCH(expression, value1, result1, [value2, result2], ..., [default_result])
  • expression: This is the value you want to evaluate.
  • value1, value2, ...: These are the values to compare against the expression.
  • result1, result2, ...: These are the results that will be returned if the expression matches the corresponding value.
  • default_result: This optional argument will be returned if no match is found.

Example 1: Using SWITCH to Categorize Scores

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:

  • If the score is 90 or above, the student gets an "A."
  • If the score is 80 or above, the student gets a "B."
  • If the score is 70 or above, the student gets a "C."
  • Otherwise, the student gets an "F."

The formula in the Grade column evaluates the score and returns the respective grade.

Example 2: Using SWITCH to Display Days of the Week

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

Benefits of Using SWITCH Over IF

  • Readability: SWITCH is easier to read and understand compared to a long chain of nested IF statements.
  • Efficiency: It is more efficient when you have many conditions to evaluate, as it can handle multiple cases in one function.
  • Error Reduction: SWITCH reduces the chances of making mistakes in complex logical conditions.

Conclusion

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.

Related Videos