Turn codes into names with SWITCH
PremiumIn C2, use SWITCH to turn the code in B2 into a name: "N" is "North", "S" is "South", and any other code is "Other".
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Order | Region code | Region | |||
| 2 | 1042 | S | ||||
| 3 | ||||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 | ||||||
| 8 |
Premium lesson
Unlock IFS and SWITCH and every other lesson
This is a premium lesson. Premium lets you solve it and every other lesson, take the timed mock tests, and earn certificates you can share on LinkedIn.
Next with premium:Conditional formattingDrop-down lists and data validation
Need help?
Why this works
SWITCH compares B2 with each value in turn: "N" does not match, "S" does, so it returns "South". The last argument has no value before it, so it is the default for every other code. Without it, an unknown code gives #N/A.
Common mistake: Writing tests like B2="N" inside SWITCH. SWITCH does the comparing itself; it wants the value, "N".
The answer
- C2
=SWITCH(1B2,2"N",3"North",4"S",5"South",6"Other")
In plain words: Look at 1the code in B2: 2N gives 3North, 4S gives 5South, and 6any other code gives Other.
Use SWITCH when you compare one cell with exact values, like codes. Use IFS when the tests are ranges or different conditions.