Sub topic 7
SWITCH(TRUE, ...) as an alternative to IFS
This chapter assumes you can write IFS formulas with a final TRUE fallback, and that you know SWITCH compares one expression to exact values. You should also be comfortable with comparison operators such as >= and <>. Here you will see how SWITCH can run condition tests like IFS, where the two behave differently, and which one to choose.
The idea in one line
SWITCH evaluates its first argument once and compares it to each case value, from left to right. It returns the result paired with the first case that equals it. If you set the first argument to TRUE, every case value can be a condition such as B2>=90. A condition evaluates to TRUE or FALSE, so the first condition that is true equals your expression and wins.
=SWITCH(TRUE,B2>=90,"A",B2>=80,"B",B2>=70,"C","F")Read this as: "Find the first case that equals TRUE. Return its result. If none does, return F."
Compare it with the IFS version of the same grading rule:
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")Both formulas return the same grade for every numeric score. The difference is in how the fallback is written.
How the arguments line up
SWITCH takes an expression, then pairs of (case, result), then an optional default. In SWITCH(TRUE, ...) the pairs are (condition, result).
| Position | In the example | Role |
|---|---|---|
| 1 | `TRUE` | The value every case is compared against |
| 2 and 3 | `B2>=90`, `"A"` | First condition and its result |
| 4 and 5 | `B2>=80`, `"B"` | Second condition and its result |
| 6 and 7 | `B2>=70`, `"C"` | Third condition and its result |
| 8 | `"F"` | Default, used when no condition is true |
The default is a single unpaired argument at the end, so the total number of arguments is even plus one: 1 + 2n + 1. If you leave out the default and no condition is true, SWITCH returns #N/A, just as IFS does without a TRUE fallback.
Order still decides the result
SWITCH(TRUE, ...) stops at the first condition that is true, exactly as IFS does. With the conditions in the wrong order, a score of 95 gets the wrong grade:
=SWITCH(TRUE,B2>=70,"C",B2>=80,"B",B2>=90,"A","F")Here 95 satisfies B2>=70 first, so the formula returns "C". Put the strictest condition first when you test with >=. When you test with <, put the smallest threshold first.
An alternative is to make the conditions mutually exclusive, so order stops mattering:
=SWITCH(TRUE,B2>=90,"A",AND(B2>=80,B2<90),"B",AND(B2>=70,B2<80),"C","F")This is longer and harder to maintain. Ordered conditions with a default are usually clearer, as long as you add a comment or a note beside the formula that says the order is intentional.
What a blank or text cell does
A default does not guarantee a sensible answer. It only guarantees that some answer comes back. Two inputs in the grading example behave in ways that surprise people:
- A blank
B2counts as 0 in a comparison. Every condition is false, so the formula returns the default"F". A missing score looks like a failing score. - A text value in
B2, such as"absent", is treated by Sheets as greater than any number in a comparison."absent">=90isTRUE, so the formula returns"A".
The second case is the dangerous one, because nothing looks wrong. Guard the input with its own first condition:
=SWITCH(TRUE,NOT(ISNUMBER(B2)),"Check score",B2>=90,"A",B2>=80,"B",B2>=70,"C","F")The guard sits first, so a blank or text cell is caught before any threshold test runs. ISNUMBER returns FALSE for both. This is better than wrapping the whole formula in IFERROR, because the bad input never produced an error. Chapter material on IFERROR later in this tutorial explains why that matters.
Conditions that use more than one cell
Because each case can be any expression that returns TRUE or FALSE, you can combine cells with AND and OR:
=SWITCH(TRUE,
AND(B2>=90,C2="Yes"),"Honors",
B2>=70,"Pass",
"Fail")Sheets allows line breaks inside a formula, so you can lay the pairs out on separate lines for readability. Press Ctrl+Enter (Cmd+Enter on Mac) in the formula bar to insert one. The line breaks do not change the result.
IFS handles this case equally well. Nothing about multi-cell conditions favors one function over the other.
Where SWITCH(TRUE, ...) and IFS differ
The two functions give the same answer for ordinary cases. The differences are in the details.
| Aspect | `IFS` | `SWITCH(TRUE, ...)` |
|---|---|---|
| Fallback | Add a final `TRUE,"value"` pair | Last unpaired argument is the default |
| Missing fallback | `#N/A` | `#N/A` |
| Argument count | Always even (condition and value pairs) | Always odd (expression, pairs, optional default) |
| Cases must be booleans | Conditions that are not logical tests cause `#VALUE!` | A case that is not boolean `TRUE` simply does not match |
| Reads as | "Test these conditions in order" | "Compare this value to these cases" |
The row on non-boolean cases deserves care. In IFS, a condition such as "yes" is not a logical value, and the formula reports an error. In SWITCH(TRUE, ...), a case such as "yes" is not equal to TRUE, so it is skipped without any message. A typo that leaves out the comparison, for example SWITCH(TRUE,B2,"A",...) where B2 holds the number 95, silently never matches. The same mistake in IFS is reported as an error, which is easier to find.
When to prefer which
Use SWITCH(TRUE, ...) when:
- You want the fallback to be a plain last argument instead of a
TRUE,"value"pair that a reader might not recognize as a fallback. - The same sheet already uses
SWITCHfor exact-match lookups and you want a consistent shape.
Use IFS when:
- The formula only has conditions and no exact-value matches.
IFSsays what it does. - You want non-logical conditions to produce a visible error instead of passing silently.
- Other people maintain the sheet. More of them know
IFS, andSWITCH(TRUE, ...)is an idiom that looks odd until you have seen it.
If the decision is really "does this cell equal one of several exact values," use ordinary SWITCH with the cell as the first argument, with no TRUE trick. That is the case SWITCH was designed for.
A worked example
A support team labels tickets by hours open. Column B holds hours. The rule is: under 4 is "On track", 4 up to but not including 24 is "Due today", 24 or more is "Overdue", and anything that is not a number needs review.
=SWITCH(TRUE,
NOT(ISNUMBER(B2)),"Needs review",
B2<4,"On track",
B2<24,"Due today",
"Overdue")Trace three rows:
B2is 2. The guard is false,2<4is true, so the result isOn track.B2is 10. The guard and10<4are false,10<24is true, so the result isDue today. The condition did not needB2>=4because the earlier test already ruled out values under 4.B2is the text"pending".ISNUMBERis false, soNOT(...)is true and the result isNeeds review. Without the guard,"pending"<4is false and"pending"<24is false, so the formula would returnOverdue.
The third row shows why the default should be the last resort and not the place where unexpected input ends up.
Exercise
A sheet has scores in column B. You write =SWITCH(TRUE,B2>=80,"Pass",B2>=50,"Borderline","Fail"). A teacher types the word "absent" into B5. What does B5's formula return, and how would you change the formula so that it returns "Check score" instead?
Show answer
It returns "Pass". In Google Sheets, text compares as greater than any number, so "absent">=80 is TRUE and the first case matches. Add a guard as the first pair: =SWITCH(TRUE,NOT(ISNUMBER(B2)),"Check score",B2>=80,"Pass",B2>=50,"Borderline","Fail"). A blank cell is also caught by the guard, because ISNUMBER of an empty cell is FALSE.
Exercise
Rewrite =IFS(B2>=90,"A",B2>=80,"B",TRUE,"F") as SWITCH(TRUE, ...). Then say what each version returns when B2 is 75, and what happens to each if you delete the fallback ("F" and, for IFS, the TRUE before it).
Show answer
SWITCH version: =SWITCH(TRUE,B2>=90,"A",B2>=80,"B","F"). Both versions return "F" for 75. If you delete the fallback, both formulas return #N/A for 75, because no condition is true and no default exists.