SWITCH

Returns the first matching value from a list of values and corresponding results with a specified value.

The SWITCH function expects the first argument to be the value to test, then pairs of values and results. The first value that matches the test value causes the function to return the corresponding result. If no results are found and a default value is provided, the function returns the default value; if no value is found and no default is provided, the function returns #ERROR!.

Syntax

=SWITCH(test, value1, result1)

=SWITCH(test, value1, result1, default)

=SWITCH(test, value1, result1, ..., valueN, resultN, default)

Arguments

ArgumentTypeDescription
testAnyThe test value to check against each value
valueAnyThe value to compare against the test value.
resultAnyThe result for the corresponding value.
defaultAny(Optional) The default value to return if no values match the test value.

Examples

=SWITCH(@"Property 1", 0, "A", 1, "B", "C")"B"
Compares the shape data property value "Property 1" (1) against 0 (and returns "A" if it matches), then against 1 (and returns "B" if it matches), and then, if nothing matches, returns "C". Because "Property 1" is equal to 1, the function returns "B".

=SWITCH(@"Property 2", 0, "A", 1, "B", "C")"C"
Compares the shape data property value "Property 2" (2) against 0 (and returns "A" if it matches), then against 1 (and returns "B" if it matches), and then, if nothing matches, returns "C". Because "Property 1" is equal to 2 and doesn't match any of the values, the function returns "C".