Sub topic 14
Handling #DIV/0! in AVERAGEIFS
This chapter explains why AVERAGEIFS returns #DIV/0!, how to tell a harmless case from a real problem, and how to handle each one. It assumes you can write AVERAGEIFS formulas with range and criteria pairs, you know IFERROR, and you understand absolute and mixed references.
Why the error appears
AVERAGEIFS divides the sum of the matching values by the number of matching values. If nothing matches, the count is zero and Excel reports #DIV/0!. SUMIFS and COUNTIFS do not have this problem. With no matches, SUMIFS returns 0 and COUNTIFS returns 0.
The chapter uses the sales layout from earlier, with Region in column B, Product in column C, and Amount in column D. These four rows are the only ones shown, and the formulas below refer to them:
A: Date B: Region C: Product D: Amount E: Notes
2025-01-05 West Laptop 1200
2025-01-09 East Monitor 300 Backorder
2025-02-02 West Monitor 310
2025-02-14 North Laptop 1150 GiftThis formula works because West has matching rows:
=AVERAGEIFS(D2:D100, B2:B100, "West")Among the rows shown, the West amounts are 1200 and 310, so the result is 755. Now ask for a region with no rows:
=AVERAGEIFS(D2:D100, B2:B100, "South")This returns #DIV/0!. Nothing is wrong with the formula. The data simply has no South rows.
Causes of an empty match set
The error can mean one of four things.
- No such rows exist. This is the legitimate case, such as a region with no sales this month.
- The criteria do not match the data. A typo, a trailing space in the data (
"West "), or a wrong operator leaves zero matches. - The matching cells in the average range are not numbers. AVERAGEIFS ignores empty cells and text in the average range. If every matching Amount is blank, or is a number stored as text, the usable count is zero.
- A previous filter or date window is too narrow. For example, the end date is earlier than the start date.
The first cause is expected, and you can hide it. The other three are data problems, and hiding them can conceal a mistake.
Decision flow
Fix 1: IFERROR
IFERROR returns a replacement when its first argument is an error:
=IFERROR(AVERAGEIFS(D2:D100, B2:B100, "South"), "No sales")This is short and works for quick reports. It has a drawback: IFERROR catches every error, not only #DIV/0!. If you later change a range so the sizes differ, AVERAGEIFS returns #VALUE!. IFERROR then shows "No sales" and hides the broken formula.
Fix 2: test the count first
A more precise guard checks whether anything can be averaged before calculating:
=IF(COUNTIFS(B2:B100, "South", D2:D100, "<>") = 0, "No sales", AVERAGEIFS(D2:D100, B2:B100, "South"))The "<>" criterion counts only non-empty Amount cells, which matches what AVERAGEIFS can average. Other errors, such as #VALUE!, still appear, so real mistakes stay visible.
The cost is that the criteria appear twice. If you change one copy and forget the other, the guard and the average disagree. Keep both pairs in cells so you edit them once:
=IF(COUNTIFS($B$2:$B$100, $G2, $D$2:$D$100, "<>") = 0, "No sales", AVERAGEIFS($D$2:$D$100, $B$2:$B$100, $G2))Here G2 holds the region name, and both functions read it.
Guarding fixes only one error
The IF(COUNTIFS(...)=0, ...) guard handles the #DIV/0! case. It does not change how text criteria work. If G2 contains "South " with a trailing space, COUNTIFS counts zero and you get "No sales" even though South rows exist. Use TRIM on typed inputs, or check the data for stray spaces.
Choosing the replacement value
What the guard returns matters to everything that uses the cell.
| Replacement | Good for | Risk |
|---|---|---|
| `"No sales"` (text) | Reports people read | Arithmetic such as `=H2*2` returns `#VALUE!` |
| `""` (empty text) | Clean-looking tables | Looks blank but is text, so `H2+1` returns `#VALUE!` |
| `0` | Totals that must stay numeric | Reads as an average of zero, which is false |
| `NA()` | Charts, which skip `#N/A` points | Shows `#N/A` in the sheet |
Zero is the most common mistake. An average of 0 and "no data" are different facts, and a later formula cannot tell them apart. Prefer text or NA() unless a downstream formula needs a number.
Functions that ignore text, such as AVERAGE, SUM, and COUNT, skip text results when you give them a range. They do not work if you reference the cell with +.
Applying the guard to a summary grid
A region-by-product grid is where #DIV/0! shows up most, because some combinations have no rows. With regions down column G and products across row 1 starting at H, this formula copies across and down:
=IFERROR(AVERAGEIFS($D$2:$D$100, $B$2:$B$100, $G2, $C$2:$C$100, H$1), "-")In the sample rows, East with Laptop has no match, so that cell shows -. West with Laptop shows 1200, and North with Laptop shows 1150.
For a grid, IFERROR is usually acceptable because the ranges are locked with $ and unlikely to change. If you use an Excel table, the guard looks like this:
=IFERROR(AVERAGEIFS(Sales[Amount], Sales[Region], $G2, Sales[Product], H$1), "-")Diagnosing a surprising #DIV/0!
When the error appears and you expected data, work through these checks in order.
- Run COUNTIFS with the same criteria pairs, leaving out the average range. If it returns 0, the criteria do not match any rows.
- Count the matching amounts:
=COUNTIFS(B2:B100, "West", D2:D100, "<>"). If the first count is above 0 and this one is 0, the matching Amount cells are empty. - Test whether the Amount cells are numbers with
=COUNT(D2:D100). If it is smaller than the number of filled cells, some amounts are text. A green triangle in the cell corner often confirms this. - Look at the criteria cell. Copy it into a formula as
=LEN(G2)and compare with the visible text length to find hidden spaces. - For date windows, confirm the start is before the end. Remember the end in the earlier date pattern is exclusive, using
"<".
Summary of options
| Situation | Approach |
|---|---|
| Quick report, ranges are locked | `IFERROR(AVERAGEIFS(...), "No sales")` |
| Result feeds decisions, or ranges change often | `IF(COUNTIFS(...)=0, ..., AVERAGEIFS(...))` |
| Result feeds a chart | Return `NA()` for empty cases |
| Unexpected error | Run the diagnosis steps above before adding a guard |
Exercise
A sheet has Region in B2:B100 and Amount in D2:D100. Cell G2 holds a region name. Write a formula that returns the average Amount for that region, or the text "No data" when the region has no numeric amounts. It must not hide a #VALUE! caused by mismatched ranges.
Show answer
=IF(COUNTIFS($B$2:$B$100, $G2, $D$2:$D$100, "<>") = 0, "No data", AVERAGEIFS($D$2:$D$100, $B$2:$B$100, $G2)). The COUNTIFS part counts rows that match the region and have a non-empty Amount, which is what AVERAGEIFS can average. Mismatched ranges would still make AVERAGEIFS or COUNTIFS return #VALUE!, so the problem stays visible instead of being replaced with "No data".
Exercise
AVERAGEIFS(D2:D100, B2:B100, "West") returns #DIV/0!, but COUNTIFS(B2:B100, "West") returns 12. Give two likely causes and one check for each.
Show answer
First, the West rows may have blank Amount cells. Check with =COUNTIFS(B2:B100, "West", D2:D100, "<>"); a result of 0 confirms it. Second, the Amounts may be numbers stored as text, so AVERAGEIFS ignores them. Check with =COUNT(D2:D100) and compare it to the number of filled cells, or look for green triangles; convert the text to numbers to fix it.