Excel SWITCH Function (Table of Contents)
SWITCH Function in Excel
The switch function in Excel is used to compare one value with the values of another list and returns the first matched value if found. This function also considers and allows the user to enter the optional default value if there is no match found. In other words, the Switch function matches the multiple values but returns only the first value out of the selected range. This is quite useful when we have duplicate values, and out of those, we want only the first value to be returned.
The Syntax of the SWITCH function includes 4 parameters. Out of 4 parameters of SWITCH functions, 3 are mandatory, and the fourth one is optional based on our requirement.
- Expression: This is simply the value or cell we are trying to test the logic.
- Value1: This the test value or logical value comparing to the Expression. We can give 126 logical tests.
- Result1: If the first logical test is true, what should be the result we want.
- Default or Value 2: Here, we can see two things. One is Default; if the first logical test is FALSE, what is the default value we want. The second one is Value2; this is the second logical test for the Expression.
- Result 2: This is the result of the second logical test we are testing.
How to Use SWITCH Function in Excel?
Using the SWITCH Function in Excel is very easy. Let’s understand the Function in Excel by some examples given below.
SWITCH Function in Excel – Example #1
As I said at the beginning, SWITCH is an alternative to the IF condition in excel. We will now see how the simple IF condition works and compare the SWITCH with the IF condition in excel.
I have a few fruit names here. I have 4 fruit names from cell A2 to A5 in excel.
Each fruit has its own status here; the status is based on how they impact human body temperature. Let me apply the IF condition to test the results. The formula for this method is :
=IF (A2=”Apple”, “Medium”, IF(A2=”orange”, “Cold”, IF(A2=”Sapota”, “Heat”, IF(A2=”Watermelon”, “Cold”, “???”))))
IF function tests if the value in the cell A2 is equal to Apple, then the result should be Medium. If the result is false, then again one more IF condition will test if the value in the cell A2 is equal to Orange, the result should be Cold; if the result is again false, then one more IF condition will tests if the value in the cell A2 is equal to Sapota then the value will be Heat and so on. Finally, if none of the conditions is TRUE, then it will return the result as ???
Like this IF condition tests multiple criteria’s and gives the result based on the logical tests. In the above example, we have applied totally 4 different IF conditions to get the result; this why we call it a nested IF condition.
However, the SWITCH function can replace those many IF conditions and can give the result in one single formula.
The formula for SWITCH Function is:
=SWITCH (A2, “Apple”, “Medium”, “Orange”, “Cold”, “Sapota”, “Heat”, “Watermelon”, “Cold”, “???”)
Now, look at the above results from the SWITCH function; it is exactly the same as the IF condition. Let me break down the formula into pieces for better understanding.
=SWITCH(A2, “Apple”, “Medium”, : This is the first argument of the function. If the cell A2 value is equal to Apple, then it will get the result as Medium.
“Orange”, “Cold”, : Unlike the IF condition, we need not to again put one more SWITCH condition here; instead, we can go on in the formula. Again, we need to mention the expression here (A2 cell) rather than simply enter the condition straight away. The condition is If the cell A2 value is equal to Orange, then the result should be Cold.
“Sapota”, “Heat”,: Similarly, if the cell A2 value is equal to Sapota, then the result should be Heat.
“Watermelon”, “Cold”, : If the cell A2 value is equal to Watermelon, then the result should be Cold.
“???”) : This is the final part of the formula. If none of the above 4 conditions is satisfied, then the result will be ???
Like this, the SWITCH function can be used as an alternative to nested IF conditions. But the SWITCH function has its own limitation, too; we will see that limitation in the below section.
SWITCH Function in Excel – Example #2
The problem with the SWITCH function is limited to exact matching only. It cannot use any kind of operators in the formulas. Some of the common operators are >=(greater than or equal to), <=(less than or equal to) etc..
Take a look at the example now. Typical examination example, I have scores and criteria.
I will apply the IF formula to determine the results.
For this, apply the formula given below:
=IF(A2>=85, “Distinction”, IF(A2>=75, “First Class”, IF(A2>=60, “Second Class”, IF(A2>=35, “Pass”, “Fail”))))
But SWITCH function cannot accept operator symbols to determine the result, and still, we have to rely on nested IF conditions to get the results.
Things to Remember
- SWITCH Function in Excel works only for exact matching.
- In the case of the operator, a symbol to determine the logic, we have to rely on IF conditions.
- SWITCH Function in Excel can handle 126 logical tests and results, but IF is limited to 64 conditions.
- It is recommended to use the SWITCH Function in exact match scenarios or use nested IF conditions.
This has been a guide to SWITCH Function in excel. Here we discuss how to use the SWITCH Function in excel and its limitations, along with practical examples and a downloadable excel template. You can also go through our other suggested articles–