Sub topic 12
Handling no matches with IFERROR
This chapter covers what happens when no row meets your conditions, why only AVERAGEIFS fails, and how to handle it. It assumes you can write COUNTIFS, SUMIFS, and AVERAGEIFS formulas with one or more criteria pairs and can use absolute references such as $A$2:$A$100. The examples use this layout: Region in column A, Product in B, Date in C, Units in D, Revenue in E, with data in rows 2 to 100.
What each function returns when nothing matches
A criteria set can match zero rows. This happens when you type a region that does not exist, when a date window contains no sales, or when a typo hides a value. The three functions respond differently.
| Function | Result when no row qualifies | Why |
|---|---|---|
| COUNTIFS | 0 | Counting zero rows is a valid count. |
| SUMIFS | 0 | The sum of nothing is 0. |
| AVERAGEIFS | #DIV/0! | An average is a sum divided by a count, and the count is 0. |
Only AVERAGEIFS needs special handling, because 0 is a reasonable answer for the other two. The #DIV/0! error is also contagious. Any formula that refers to the cell, such as a total, a chart series, or a percentage, shows the error as well.
AVERAGEIFS can also return #DIV/0! when rows do match. This happens when every matching cell in the average range is empty or contains text, because those cells are ignored and nothing is left to average.
=AVERAGEIFS(E2:E100, A2:A100, "Nowhere")This formula returns #DIV/0! because no row has the region "Nowhere".
IFERROR: the syntax
IFERROR checks a formula and replaces any error with a value you choose.
=IFERROR(value, value_if_error)valueis the formula to evaluate. If it returns a normal result, IFERROR passes that result through unchanged.value_if_erroris what to show ifvaluereturns an error. If you leave it out, Sheets shows an empty cell.
Wrapping AVERAGEIFS looks like this:
=IFERROR(AVERAGEIFS($E$2:$E$100, $A$2:$A$100, G2), "No matches")Here G2 holds a region name. If the region has rows, you get the average. If not, the cell shows "No matches". The absolute references ($E$2:$E$100) keep the ranges fixed when you fill the formula down a column of regions. The relative reference G2 moves to G3, G4, and so on.
Choosing the fallback value
The fallback is a design decision, because it affects every cell that depends on the result.
| Fallback | Example | Good for | Risk |
|---|---|---|---|
| Text | `"No matches"` | Reports people read directly | Text in a cell can break later arithmetic. |
| Empty string | `""` | Clean-looking tables | The cell looks empty but still holds text, so `ISBLANK` returns FALSE. |
| 0 | `0` | Cells that feed totals | A real average of 0 and "no data" look identical. |
| Omitted | `IFERROR(x)` | A truly empty cell | Same appearance as a cell you forgot to fill. |
Use 0 with care. An average of 0 means rows existed and their values were 0. "No data" means no rows existed. Showing both as 0 can mislead readers.
The risk: IFERROR hides every error
IFERROR does not look at which error occurred. It replaces all of them. That includes errors that signal a real mistake in your formula:
- #VALUE! from ranges of different sizes, such as
A2:A100paired withE2:E99. - #REF! from a deleted column.
- #NAME? from a misspelled function name.
- #N/A and others from a broken reference.
Suppose you wrap a formula that has a range-size mismatch. The formula fails on every row, and IFERROR turns each failure into "No matches". The report looks healthy and is wrong everywhere. The same thing happens if you accidentally delete a column the formula uses.
A narrower alternative: test the count first
You can handle only the no-match case by checking the count of qualifying rows before averaging. COUNTIFS accepts the same criteria pairs, so the check mirrors the formula it protects.
=IF(COUNTIFS($A$2:$A$100, G2) = 0, "No matches", AVERAGEIFS($E$2:$E$100, $A$2:$A$100, G2))If the count is 0, the cell shows "No matches". Otherwise AVERAGEIFS runs. Other errors still appear, so a range-size mismatch stays visible. The cost is that the criteria appear twice, which makes the formula longer and means you must update both copies when conditions change.
This version does not catch the case where rows match but every matching Revenue cell is blank. The count is above 0, and AVERAGEIFS still returns #DIV/0!. If that case matters in your data, check the numeric count of the average range instead:
=IF(COUNTIFS($A$2:$A$100, G2, $E$2:$E$100, "<>") = 0, "No matches", AVERAGEIFS($E$2:$E$100, $A$2:$A$100, G2))The extra pair $E$2:$E$100, "<>" counts only rows where Revenue is not empty. It treats a cell holding text as non-empty, so a text entry in Revenue can still slip through.
| Approach | Catches no matches | Catches all-blank matches | Hides other errors |
|---|---|---|---|
| IFERROR wrapper | Yes | Yes | Yes |
| IF with COUNTIFS on the criteria | Yes | No | No |
| IF with COUNTIFS including the average range | Yes | Mostly | No |
Choosing between them
Use IFERROR for a quick, readable summary table once the formula is verified. Its short form is easy to fill down and maintain. Use the IF and COUNTIFS version when the sheet is shared, long-lived, or feeds other calculations, because errors that signal real problems stay visible.
Also consider whether you need either one. If you only want to know whether anything matched, a COUNTIFS cell next to the average serves the same purpose and shows the number of rows behind each average. Readers can then judge whether an average of two rows deserves the same trust as an average of two hundred.
Putting it into a summary table
A typical table lists regions in column G and shows the count, total, and average beside each. Only the average needs protection:
=COUNTIFS($A$2:$A$100, G2)
=SUMIFS($E$2:$E$100, $A$2:$A$100, G2)
=IFERROR(AVERAGEIFS($E$2:$E$100, $A$2:$A$100, G2), "No matches")Put these in H2, I2, and J2, then fill down. A region with no rows shows 0, 0, and "No matches", which reads clearly and keeps the count visible next to the average.
Exercise
A formula =IFERROR(AVERAGEIFS(E2:E100, A2:A99, "West"), "No matches") shows "No matches" for every region, even though West rows exist. What is wrong, and how would you find it?
Show answer
The ranges have different sizes (E2:E100 has 99 rows, A2:A99 has 98), so AVERAGEIFS returns #VALUE!. IFERROR replaces that error with "No matches" and hides it. Remove the IFERROR wrapper and the #VALUE! appears. Then change both ranges to the same rows, for example E2:E100 and A2:A100.
Exercise
Write a formula that shows "No matches" when no West row has at least 10 units, and otherwise averages Revenue for those rows. Use the IF and COUNTIFS approach so that other errors stay visible. Ranges are A (Region), D (Units), and E (Revenue), rows 2 to 100.
Show answer
=IF(COUNTIFS($A$2:$A$100, "West", $D$2:$D$100, ">=10") = 0, "No matches", AVERAGEIFS($E$2:$E$100, $A$2:$A$100, "West", $D$2:$D$100, ">=10"))