What is Switch Function in MS Excel?
The SWITCH function comes under the category of logical functions in MS Excel. It is used to evaluate a value or an expression against a list of expressions or values.
Purpose of SWITCH Function in Excel
The purpose of the SWITCH function in MS Excel is to test a given value or expression against a list of values. It will return the value when the value in the list will match with the given value or expression. If there is no match with the given value, then a default value will be returned as the result. This function has reduced the need for a nested IF function.
Syntax of SWITCH Function
The SWITCH function in MS Excel is written as follows.
=SWITCH (expression, value1, result1, [default or value2, result2],…[default or value3, result3])
The arguments in the Switch function are described below.
Expression: this is the value or expression which is used for matching from the list.
Value 1, result 1: this is the first pair of values and its corresponding result.
Value2, result 2: this is the second pair of values and its corresponding result.
Default: this is the value that will be returned if there is no match of the expression with the values in the list.
=SWITCH (WEEKDAY(A2),1, “Sunday”,2, “Monday”,3, “Tuesday”, “No match”)
The above example will return the result Monday according to the values.