Logic and errors function
SWITCH function in Google Sheets and Excel
SWITCH compares one value with a list of exact matches and returns the result paired with the first match, or a default.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
SWITCH(expression, value1, result1, [default or value2, result2], …)Arguments in [brackets] are optional. Google Sheets writes it SWITCH(expression, case1, value1, [default or case2, value2], …).
Example
=SWITCH(D2,"Basic","B","Pro","P","Team","T","?") reads: Look at the plan in D2: Basic becomes B, Pro becomes P, Team becomes T, and anything else becomes ?.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Name | Age | Plan | Joined | Code | |
| 2 | mara@example.com | Mara | 34 | Pro | 12 Jan 2026 | P |
| 3 | jonas@example.org | Jonas | 41 | Basic | 15 Jan 2026 | B |
| 4 | MARA@example.com | Mara O. | 34 | Pro | 20 Jan 2026 | P |
| 5 | priya@example.net | Priya | Team | 2 Feb 2026 | T | |
| 6 | tomas@example.com | Tomás | n/a | basic | 9 Feb 2026 | B |
| 7 | elif@example.org | Elif | 29 | Pro | 17 Feb 2026 | P |
| 8 | jonas@example.org | Jonas Lind | 41 | Basic | 23 Feb 2026 | B |
| 9 | kenji@example.net | Kenji | 52 | Enterprise | 3 Mar 2026 | ? |
| 10 | sofia@example.com | Sofia | 23 | Team | 8 Mar 2026 | T |
| 11 | leo@example.org | Leo | 17 | Basic | 14 Mar 2026 | B |
F2 shows P for Mara's Pro plan; row 9's Enterprise isn't in the list, so it falls through to the default, ?.
How the spreadsheet calculates it
Compares D2 with each case and returns the matching result: "Basic" → "B", "Pro" → "P", "Team" → "T"; anything else → "?".
- 1. SWITCH: Compares
D2with each case and returns the matching result:"Basic"→"B","Pro"→"P","Team"→"T"; anything else →"?".value=`D2`: the cell to look atmatch1=`"Basic"`: a value it might equalresult1=`"B"`: what to show when it does. Add more match/result pairsdefault=`"Pro"`: optionaldefault=`"P"`: optionaldefault=`"Team"`: optionaldefault=`"T"`: optionaldefault=`"?"`: optional
More SWITCH examples
=SWITCH(D2,"Basic","B","Pro","P","Team","T","?")A letter per plan, ? for anything else.=SWITCH(WEEKDAY(A2,2),6,"Weekend",7,"Weekend","Weekday")Weekend or Weekday from a date.=SWITCH(B2,"N","North","S","South","Unknown")Region names from one-letter codes.
Paste any of these into the formula explainer to see it step by step.
Tips
- Always end with a default, so new codes in the data show something readable instead of #N/A.
- Clean the value first (TRIM, UPPER) if the data may contain stray spaces or mixed case.
- Move long code lists into a two-column table and use XLOOKUP, so updating a label doesn't mean editing the formula.
- SWITCH compares exact values only; for bands like “70 and above”, use IFS or an approximate lookup instead.
What SWITCH is used for
Turning codes into labels (plan codes, region codes, status numbers), mapping weekday numbers to names, and replacing chains of IF that compare the same cell with different values.
Arguments
| Argument | Required | What it is |
|---|---|---|
| expression | Yes | The value to compare, usually a cell. |
| value1, result1 | Yes | A value it might equal, and what to return if it does. Add more pairs. |
| default | No | A last, unpaired argument: returned when nothing matches.Watch out: Without it, an unmatched value gives #N/A. |
Common mistakes
Using SWITCH for ranges like “at least 70”: it only does exact matches. Use IFS.
Using SWITCH for ranges like “at least 70”: it only tests exact equality. Use IFS or an approximate lookup.
Forgetting the default, so a new value in the data shows #N/A.
In Google Sheets
Google Sheets has SWITCH with the same arguments, including the unpaired default at the end.
Errors you may see with SWITCH
Questions
SWITCH or IFS?
SWITCH when one value is compared with exact matches; IFS when each condition is its own test, like score bands. See nested IF vs IFS vs SWITCH.
Is SWITCH case-sensitive?
Microsoft's page doesn't say, and we haven't confirmed it, so don't rely on case either way; clean the text first with UPPER or PROPER.
How many pairs can SWITCH take?
Microsoft's page allows up to 126 value and result pairs. Long lists are easier to maintain as a two-column table with XLOOKUP.
Sources
Official documentation the facts on this page were checked against.