Purpose
Match multiple values, return first match
Return value
Result corresponding with first match
Arguments
expression - The value or expression to match against.
val1/result1 - The first value and result pair.
val2/result2 - [optional] The second value and result pair.
default - [optional] The default value to use when no match is found.
Syntax
=SWITCH(expression, val1/result1, [val2/result2], ..., [default])
The first argument in SWITCH is called "expression" and can be a hard-coded constant, a cell reference, or a formula that returns a specific value to match against. Matching values and corresponding results are entered in pairs. SWITCH can handle up to 126 pairs of values and results. The last argument, default, is an optional value to return when there is no match.
In the example shown, the formula in D5 is:
=SWITCH(C5,1,"Poor",2,"OK",3,"Good","?")
SWITCH only performs an exact match, so you can't include logical operators like greater than (>) or less than (<) in the logic used to determine a match. You can work around this limitation by constructing a formula to match against TRUE like this:
=SWITCH(TRUE,A1>=1000,"Gold",A1>=500,"Silver","Bronze")
0 Nhận xét