SWITCH: one of several values
Each store has a one-letter region code. Turn the codes into region names in column C.
keyboard Typing formulas is easiest on a computer with a keyboard.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Store | Region code | Region | |
| 2 | Store 539 | NE | ||
| 3 | Store 225 | N | ||
| 4 | Store 463 | E | ||
| 5 | Store 322 | E | ||
| 6 | Store 239 | N | ||
| 7 | Store 540 | W | ||
| 8 | Store 160 | S | ||
| 9 | Store 455 | W | ||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 |
How SWITCH works
What does
SWITCHdo?SWITCHlooks at one value and compares it with a list. When it finds a match, it returns the result paired with it:=SWITCH(B2,"N", "North", "S", "South", "Unknown") How do you read it?
- First, the value to check:
B2. - Then pairs: a value to match, and the result for it. "N" gives "North", "S" gives "South".
- Last, on its own, the default: what to show when nothing matches.
- First, the value to check:
What if there is no default?
A value that matches nothing gives #N/A. Adding a default such as "Unknown" catches typos and new codes.
Why not nested IFs?
=IF(B2="N","North",IF(B2="S","South",...))works, but every extra code adds anotherIFand another bracket.SWITCHnamesB2once and lists the pairs, so it is easier to read and to extend. UseIFSinstead when the questions are different, such asB2>=70, not one value matched against a list.Does case matter?
No. "n" matches "N", just as it does with =.
Know someone fighting with a spreadsheet? Send them this page.