The SWITCH function
Compares one value against a list and returns the result for the first match, with an optional default at the end.
Syntax
SWITCH(expression, value1, result1, [value2, result2], ..., [default])- expression
- The value to compare.
- value1, result1
- A value to match and the result to return for it.
- default (optional)
- What to return when nothing matches. Without it SWITCH returns #N/A.
Examples
C1
=SWITCH(1A2,2"DK",3"Denmark",4"SE",5"Sweden",6"Other")| A | B | C | |
|---|---|---|---|
| 1 | Code | Denmark | |
| 2 | DK |
In plain words: Look at 1the code in A2: 2if it is DK, 3show Denmark; 4if it is SE, 5show Sweden; 6otherwise show Other.
C1=SWITCH(A2,"NO","Norway","Other")
| A | B | C | |
|---|---|---|---|
| 1 | Code | Other | |
| 2 | DK |