Sub topic 8
Choosing between IF, IFS, and SWITCH
This chapter assumes you can enter and edit formulas in Google Sheets and use cell references such as B2. It also assumes you know the comparison operators (=, <>, >, >=, <, <=) and the basic IF function. You have already seen how IFS and SWITCH work on their own. Here the question is which one to reach for.
Three functions, three kinds of decision
All three functions turn a test into a result. They differ in the kind of test they are built for.
IFmakes one yes-or-no decision. It has one test, one result for true and one result for false.IFSmakes a decision with several tiers. Each tier has its own condition, and the first true condition wins.SWITCHcompares one expression to a list of exact values and returns the result paired with the match.
The deciding question is what the tests look like. If you are asking "is this value in a range or does it meet a condition?", you want IF or IFS. If you are asking "is this value exactly one of these?", you want SWITCH.
| Situation | Best fit | Why |
|---|---|---|
| One condition, two outcomes | `IF` | Nothing simpler exists |
| Several ranges or thresholds on a number | `IFS` | Each tier is its own condition |
| Exact codes mapped to labels | `SWITCH` | The expression is written once |
| Conditions on different cells | `IFS` | Each condition can point at a different cell |
| More than a few dozen exact pairs | A lookup table | The mapping becomes data, not a formula |
When IF is enough
Use IF when there are only two outcomes. Wrapping it in something larger adds noise without adding power.
=IF(B2>=70,"Pass","Fail")A common mistake is to reach for IFS here. IFS with one condition and a TRUE fallback does the same work, but it is longer and harder to read.
=IFS(B2>=70,"Pass",TRUE,"Fail")Both formulas return the same result. Prefer the first one.
When IFS is the right choice
Use IFS when the decision has three or more outcomes and the tests are ranges or comparisons. A letter grade is the standard case. The nested version works, but each tier adds another IF( and another closing parenthesis.
=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F")))IFS lists the same tiers as flat pairs, and the final TRUE condition catches every remaining score.
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")IFS has two properties that SWITCH does not have.
- Each condition is a full test, so it can use
>,<,>=,<=, and<>. - Each condition can refer to a different cell, or to several cells at once with
ANDandOR.
The second property matters when the tiers depend on more than one value:
=IFS(AND(B2>=90,C2="Yes"),"A with honors",B2>=90,"A",B2>=80,"B",TRUE,"Below B")SWITCH cannot do this directly, because it compares only one expression.
Remember that order matters in IFS. The first true condition wins, so list the most specific or highest threshold first. Always end with TRUE unless you want #N/A for unmatched input.
When SWITCH is the right choice
Use SWITCH when one value is compared to a list of exact matches. A state code is the usual example.
=SWITCH(A2,"NY","New York","CA","California","TX","Texas","Unknown")The equivalent IFS formula repeats A2 in every condition:
=IFS(A2="NY","New York",A2="CA","California",A2="TX","Texas",TRUE,"Unknown")The SWITCH version is shorter, and there is only one place to change if the source cell moves. The final unpaired argument is the default, so the "no match" case is built in and needs no TRUE trick.
SWITCH also accepts a function as its expression. Here it groups weekend days and returns a default for everything else:
=SWITCH(WEEKDAY(A2),1,"Sunday",7,"Saturday","Weekday")The function runs once and the result is compared to each case value.
SWITCH is for exact matches only
SWITCH tests equality. It cannot say "greater than 90". This formula does not do what it looks like it does:
=SWITCH(B2,">=90","A",">=80","B","F")It compares B2 to the text ">=90", which never matches a number, so every row returns "F". If the tiers are ranges, use IFS.
The SWITCH(TRUE, ...) trick
You can put TRUE in the expression slot. SWITCH then returns the result of the first condition that evaluates to TRUE.
=SWITCH(TRUE,B2>=90,"A",B2>=80,"B","F")This behaves like IFS, and the default is written as the last unpaired argument instead of TRUE,"F". It is a valid alternative, but it is less common. A colleague who sees IFS understands it immediately. Use SWITCH(TRUE, ...) when you want the built-in default, or when the sheet already uses SWITCH heavily and you want a consistent style.
A decision path
The diagram shows the questions to ask, in order.
Edge cases that change the choice
Blank cells
A blank cell is treated as 0 in numeric comparisons. With IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F"), an empty B2 returns "F", not an error. That may be wrong for your data. If blank should mean "not graded", test for it first:
=IFS(B2="","Not graded",B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")In SWITCH, a blank cell compared to 0 also matches, so a case value of 0 can catch blanks you did not mean to include.
Text case and spaces
SWITCH and = comparisons in Sheets are not case-sensitive for text, so "ny" matches "NY". Extra spaces do count. "NY " does not match "NY". If your data comes from pasted or imported text, wrap the expression in TRIM:
=SWITCH(TRIM(A2),"NY","New York","CA","California","Unknown")Numbers stored as text
The text "90" is not equal to the number 90 in a SWITCH case. If a column was imported as text, the cases will not match and every row falls to the default. Check by looking at the cell alignment (text aligns left by default), or use ISNUMBER(A2) in a helper cell.
Missing fallback
IFS with no TRUE fallback returns #N/A when nothing matches.
=IFS(B2>=90,"A",B2>=80,"B")SWITCH without a default also returns #N/A when nothing matches. In both cases, decide on purpose whether you want a fallback value or a visible error.
Comparison summary
| Feature | IF | IFS | SWITCH |
|---|---|---|---|
| Number of outcomes | 2 | 2 or more | 2 or more |
| Test type | Any condition | Any condition per tier | Equality to one expression |
| Different cell per test | Yes | Yes | No |
| Built-in default | The false branch | No, add `TRUE` | Yes, last unpaired argument |
| No match, no fallback | Not applicable | `#N/A` | `#N/A` |
| Readability with many tiers | Poor when nested | Good | Good |
A worked decision
Suppose a sheet has three needs:
- Mark an order "Late" if the days open exceed 30.
- Label a priority code (
1,2,3) as "High", "Medium", or "Low". - Assign a shipping fee of 0, 5, or 10 based on order total thresholds.
The choices follow from the questions above.
=IF(C2>30,"Late","On time")=SWITCH(D2,1,"High",2,"Medium",3,"Low","Unknown")=IFS(E2>=100,0,E2>=50,5,TRUE,10)The first is a single yes-or-no test, so IF fits. The second maps exact codes, so SWITCH fits. The third has numeric thresholds, so IFS fits.
Exercise
A column holds shipping zone codes "A", "B", and "C", and you want the labels "Local", "Regional", and "International", with "Check zone" for anything else. Which function should you use, and what is the formula for cell A2?
Show answer
Use SWITCH, because the decision maps exact values of one cell to results and needs a default. The formula is =SWITCH(A2,"A","Local","B","Regional","C","International","Check zone").
Exercise
You need a discount of 20% for totals of 500 or more, 10% for totals of 200 or more, and 0% otherwise, based on B2. Which function fits, and why does the order of the conditions matter?
Show answer
Use IFS, because the tiers are numeric ranges. The formula is =IFS(B2>=500,0.2,B2>=200,0.1,TRUE,0). The first true condition wins, so if B2>=200 came first, a total of 600 would return 10% instead of 20%.