SWITCH
The SWITCH function evaluates a value against a list, and returns a result that corresponds with either the first matching value or an optional value if there is no match.
SWITCH(expression, switch-value, if-match, [default or switch-value…], [if-match…])
expression: The list of values you want to check for a match.
switch-value: The first value to compare against expression.
if-match: The value to return if switch-value matches expression.
default or switch-value…: Optionally include the value that’s returned if there is no match for expression, or one or more additional values to compare.
if-match…: For every switch-value…, an additional if-match… must be included.
Notes
default must be the last argument in the function.
Examples |
---|
Given a table where A2=1, A3=0, and A4=-1: =SWITCH(A2,1,"Yes", "No") returns "Yes", as switch-value matched expression. =SWITCH(A3,1,"Yes", "No") returns "No", as there was no match for expression. =SWITCH(A3,1,"Yes",0, "Maybe","No") returns "Maybe", as there was a match for expression in switch-value…. =SWITCH(A4,1,"Yes",0, "Maybe","No") returns "No", as there was no match for expression in switch-value or switch-value…. |