If expression has this value the corresponding result will be returned.
Result
Repeatable
The result to be returned if Expression has corresponding value.
Else
Optional
If there are no matching values the Else value is returned.
Return Values
If there’s a match with a value, a scalar value from the corresponding result is returned. If there isn’t a match with a value, a value from else is returned. If none of the values match and else isn’t specified, BLANK is returned.
Remarks
The expression to be evaluated can be a constant value or an expression. A common use of this function is to set the first parameter to TRUE. See examples below.
All result expressions and the else expression must be of the same data type.
The order of conditions matters. As soon as one value matches, the corresponding result is returned, and other subsequent values aren’t evaluated. Make sure the most restrictive values to be evaluated are specified before less restrictive values. See examples below.
Examples
A common use of SWITCH is to compare expression with constant values. The following example creates a calculated column of month names:
Another common use of SWITCH is to replace multiple nested IF statements. This is accomplished by setting expression to TRUE, as shown in the following example, which compares Reorder Point and Safety Stock Level on products to identify potential risks of running out of stock:
The order of values matters. In the following example, the second result is never returned because the first value is less restrictive than the second. The result in this example is always A or C, but never B.
The following statement returns an error because the data types in the result arguments are different. Keep in mind that the data types in all result and else arguments must be the same.