Returns the results of an expression corresponding to the first matching value when evaluating one value against a list of values, or the results of the default expression if there is no match.
Sample usage
SWITCH([Date],TODAY(),"Today",(TODAY() - 1),"Yesterday",(TODAY() + 1),"Tomorrow", TEXT([Date]))
returns a user-friendly date string, such as Today, Yesterday, or Tomorrow.
SWITCH([Color], "Red", 3, "Yellow", 2, "Green", 1, 0)
returns a numeric value based on the color value.
SWITCH([Access Required], "Admin", IN(USEREMAIL(), Admin Users[Email]), "User", IN(USEREMAIL(), Users[Email]), FALSE)
returns the role required for access.
SWITCH(CONTEXT("Host"), "Device", "Tap below to:", "Browser", "Click below to:", "")
returns different directions depending on whether the app is running from the native app on a device or from a browser. This might be used to generate a display name for a gallery view of launchers. See also: CONTEXT()
Syntax
SWITCH(expression, case1, value1, [case2, value2 ...], default)
expression
- Value or expression of any type.case1
- First condition to be checked againstvalue
. Must be comparable type tovalue
.value1
- Expression that is evaluated and returned ifcase1
is a match.case2, value2 …
(Optional) Additional conditions and expressions if the first one doesn’t match the expression.default
- An expression that is evaluated and returned if no match is found.