Sub topic 13
Putting IFS, SWITCH, and IFERROR together
The earlier chapters introduced each function on its own. Real spreadsheets rarely need only one. A grade column needs ranges and error handling. A price column needs an exact-match lookup and a fallback for codes nobody has added yet. This chapter shows how to combine the three so the formula covers every case without hiding mistakes.
This chapter assumes you can write IFS with a TRUE fallback, write SWITCH with a default, and recognize the error values #N/A, #DIV/0!, #VALUE!, #REF!, #NAME?, and #NUM!. It also assumes you are comfortable with cell references such as B2 and with comparison operators.
What each function is responsible for
Each function handles a different kind of problem. Combining them works best when you decide which function owns which problem.
| Problem | Best tool | Why |
|---|---|---|
| Value falls in a range or meets a condition | IFS | It tests conditions in order and returns the first match. |
| Value must equal one of a known list | SWITCH | It compares one expression to exact values. |
| A value no branch anticipated | TRUE fallback in IFS, or the default in SWITCH | The formula still returns a deliberate result. |
| A formula returns an error value | IFERROR | It replaces any error with a fallback. |
| Only a missing lookup match should be handled | IFNA | It replaces #N/A and lets other errors show. |
A fallback inside IFS or SWITCH handles input that is valid but unexpected, such as a score of 40 or a state code "WY". IFERROR handles formulas that fail. These are different situations. Keeping them separate is the main design rule of this chapter.
Pattern 1: IFERROR around IFS
The simplest combination wraps IFERROR around an IFS formula that has no TRUE fallback:
=IFERROR(IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C"),"Check score")If the score is 70 or higher, IFS returns a letter. If it is below 70, no condition is true, IFS returns #N/A, and IFERROR turns that into "Check score". In this formula, every score under 70 shows "Check score". That is probably not what a gradebook wants.
Compare the version with a TRUE fallback:
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")Now a score of 40 returns "F", which is a meaningful answer. The TRUE fallback is the better tool for "no other condition matched". IFERROR around the first version is a weaker tool because it treats a normal low score as a failure.
Pattern 2: guard bad input inside IFS
Sometimes the problem is the input, not the ranges. A score cell might be blank, contain text such as "absent", or hold an error from another formula. You can handle these cases by placing a guard condition first in IFS:
=IFS(NOT(ISNUMBER(B2)),"Check score",B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")Because IFS returns the first true condition, the guard runs before any comparison. ISNUMBER returns FALSE for a blank cell, for text, and for an error value, so all three produce "Check score". Real numbers reach the grade conditions, and anything under 70 gets "F".
This version does not rely on an error to detect bad input. You do not have to guess what a comparison does with text, and the formula says what it means. It also shows why order matters again. If the guard sat at the end, a text value could match an earlier comparison first.
Pattern 3: SWITCH with a lookup that may fail
SWITCH matches exact values, and the expression it matches can be another function. When that function can fail, protect it before SWITCH sees it. Suppose column A holds product IDs, and the Products sheet maps each ID to a category code such as "H", "F", or "T":
=SWITCH(IFNA(VLOOKUP(A2,Products!A:B,2,FALSE),"?"),"H","Hardware","F","Furniture","T","Tools","Unclassified")The pieces work in this order:
- VLOOKUP looks up the product ID. If the ID is missing, it returns #N/A.
- IFNA replaces only that #N/A with "?", so SWITCH receives a plain value.
- SWITCH maps "H", "F", and "T" to names. Any other value, including "?" and codes that are not in the list, gets "Unclassified".
IFNA is used here instead of IFERROR on purpose. If someone deletes column B of the Products sheet, VLOOKUP returns #REF!. IFNA lets that error reach the cell, so you notice the broken range. IFERROR would have turned it into "Unclassified" in every row.
Pattern 4: SWITCH choosing between IFS formulas
SWITCH can return a whole formula as a result, and IFS can be one of those formulas. This is useful when the first decision is an exact match and the second is a range. A commission plan may have different thresholds for each region:
=SWITCH(A2,
"East",IFS(B2>=10000,0.10,B2>=5000,0.07,TRUE,0.05),
"West",IFS(B2>=10000,0.12,TRUE,0.06),
0)Column A holds the region and column B holds sales. SWITCH picks the region first. Each IFS then applies that region's thresholds. A region that is not listed returns the default of 0.
Line breaks inside a formula are allowed in Google Sheets. Press Ctrl+Enter (Cmd+Option+Enter on Mac) in the formula bar to add one. They make a nested formula much easier to read.
Here the alternative is a nested IF with two levels and two regions. It would be much harder to follow.
How the pieces evaluate
The next diagram shows the order of evaluation for a formula that wraps IFERROR around SWITCH, which contains IFS. The outermost function receives whatever the inner functions return, whether that is a value or an error.
Notice that the IFS branch can produce #N/A, but the SWITCH default branch cannot. The default is a deliberate answer, so IFERROR only needs to catch real failures.
Avoiding hidden errors when you combine them
Wrapping a formula in IFERROR is quick, and that makes it easy to overuse. A few habits keep combined formulas honest.
Build from the inside out. Write and test the IFS or SWITCH on its own first. Check that every case returns what you expect, including a blank input and an unmatched input. Add IFERROR or IFNA last. If you start with IFERROR, a typo such as IFSS produces #NAME?, and IFERROR will hide it behind your fallback text, so you will not see it while building.
Use a distinctive fallback. A fallback of 0 looks like real data and can silently change a SUM or an average. Text such as "Check score" or "Missing price" is visible and easy to filter for. If a numeric column must stay numeric, consider returning an empty string "" and handle it in later formulas.
Use the narrowest handler that fits. IFNA is right when only a missing match is expected. IFERROR is right when several error types are acceptable, such as a division where either input may be blank. The same formula can also use both at different levels, as in Pattern 3.
Keep error handling out of the middle of long chains. One IFERROR around the whole formula is easier to reason about than IFERROR calls scattered through each branch. When a branch needs its own handler, write it as a separate helper column so you can inspect it.
Test deliberately. Before you trust a combined formula, try these inputs:
- A value that matches each branch.
- A value that matches no branch.
- A blank cell.
- Text where a number is expected.
- A cell that itself contains an error.
The last case is the important one. IFERROR cannot tell whether the error came from your formula or from a cell it reads. Check where the error originates before you decide to hide it.
A complete example
A sheet has order rows with the region code in A, the order total in B, and the quantity in C. You want a shipping label for each row. The rules are:
- Region "EU" or "UK" is international, with a surcharge decided by total.
- Other known regions are domestic.
- A missing or non-numeric total shows "Check total".
- Anything unexpected shows a visible fallback.
=IFERROR(
IFS(
NOT(ISNUMBER(B2)),"Check total",
SWITCH(A2,"EU",TRUE,"UK",TRUE,FALSE),IFS(B2>=500,"Intl: free",TRUE,"Intl: +15"),
SWITCH(A2,"US",TRUE,"CA",TRUE,FALSE),"Domestic",
TRUE,"Unknown region"
),
"Check row")Each layer has one job:
- The guard in IFS rejects blank, text, and error totals before any comparison.
- SWITCH is used as a yes/no test for a list of region codes. It returns TRUE for listed codes and FALSE by default, which IFS can use as a condition.
- The inner IFS applies the amount threshold for international orders.
- The TRUE fallback labels unrecognized regions deliberately, so they do not turn into errors.
- IFERROR catches anything else, such as an error created by a faulty cell, and gives it a distinct label, "Check row".
Because the guard and fallback cover the known failure cases, IFERROR should rarely fire. When "Check row" does appear, it means something unexpected happened, so you can find it with a filter. A heavy count of "Check row" cells is a signal to investigate. It is not routine output.
Exercise
Column A holds a state code and column B holds a subtotal. You want the total with tax: NY is 8%, CA is 7.25%, TX is 6.25%. A code not in the list should show "Unknown state", and a text subtotal such as "n/a" should not be hidden. Write a formula using SWITCH and IFNA or IFERROR, and say which handler you chose and why.
Show answer
=IFNA(B2*SWITCH(A2,"NY",1.08,"CA",1.0725,"TX",1.0625),"Unknown state"). SWITCH has no default, so an unlisted code returns #N/A, and IFNA replaces it with "Unknown state". IFNA is the right choice because a text subtotal makes the multiplication return #VALUE!, which IFNA does not catch, so the bad subtotal stays visible. IFERROR would have labeled that row "Unknown state" as well, which would be wrong.
Exercise
What does =IFERROR(IFS(B2>=70,"C",B2>=80,"B",B2>=90,"A"),"Check score") return when B2 is 95, and when B2 is 50? Explain both results and describe one change that fixes the formula.
Show answer
For 95 it returns "C", because IFS returns the value for the first true condition and 95>=70 is checked first. For 50 it returns "Check score": no condition is true, so IFS returns #N/A and IFERROR replaces it. To fix it, order the conditions from highest to lowest (90, 80, 70) and add TRUE,"F" as the last pair if a low score should get a grade. Then use IFERROR, if at all, only for real errors.
Exercise
A formula =IFERROR(SWITCH(A2,"S","Small","M","Medium","L","Large"),"Other") shows "Other" for every row after someone deletes the lookup column that A2 depends on. What went wrong, and how would you restructure it?
Show answer
The deletion made A2 (or a formula it depends on) return #REF!, and IFERROR replaced that error with "Other", so the broken reference looked like a normal unmatched value. Restructure it by giving SWITCH its own default, as in SWITCH(A2,"S","Small","M","Medium","L","Large","Other"), and remove the IFERROR or replace it with IFNA. Then unmatched sizes show "Other" while a #REF! still appears as an error.