Compares values against a given expression and returns the corresponding result value
The SWITCH function is one of Excel's logical functions.
The SWITCH function evaluates an expression against a given value and returns the corresponding result value that you have provided.
The SWITCH function is an alternative to the IF and IFS functions.
An important difference between these functions is that SWITCH can only perform exact matching (ie "is equal to") it cannot perform greater than or lower than checks.
Let's take a look at a simple example of the SWITCH function.
We have the following business logic:
Using a nested IF statement this would be structured as follows:
=IF(A1=100,"high",IF(A1=50,"medium",IF(A1=10,"low",IF(A1=5,"extra low","not found"))))
Using the IFS function this becomes:
=IFS(A1=100,"high",A1=50,"medium",A1=10,"low",A1=5,"extra low",TRUE,"not found")
Using the SWITCH function this becomes:
=SWITCH(A1,100,"high",50,"medium",10,"low",5,"extra low","not found")
Notice the difference between how the three functions are structured.
If the value in cell A1 is equal to 100, then return “High”, otherwise if it is equal to 50, then return “medium”, otherwise if it is equal to 10, then return “low” otherwise if it is equal to 5, then return “ extra low” otherwise return "not found".
The logical tests are in pairs: The value and corresponding result:
Expression - This is the value to match against
Value 1 – The first value to check against
Result 1 – What to return if the expression matches value 1
[Value 2] – The second value to check agains
[Result 2] – What to return if the expression matches value 2
...etc...
[Default] - Optional value to return if the expression does not match any of the given values
Read more about the SWITCH function on the Microsoft support page here.