AVERAGEIFS Returns #DIV/0! When Nothing Matches
AVERAGEIFS returns #DIV/0! when no numeric values match, while SUMIFS and COUNTIFS return 0. A matched score of zero is a real average, not an error.
本文目录
AVERAGEIFS returns #DIV/0! on a grade that “should” have an average, while SUMIFS and COUNTIFS using the same criterion return 0. The criterion is not necessarily broken. A sum or a count can be zero when nothing matches; an average has nothing to divide by.
These results, and the error text quoted later, were measured in Google Sheets. I did not re-check in Excel whether AVERAGEIFS also returns #DIV/0!, so treat any Excel wording as unconfirmed.
Six functions, one missing grade
Enter this fictional community climbing-gym route-score log in A1:D10. Leave D6 genuinely empty. In D7 enter ="". In D8 enter a numeric 0. Use Automatic number formatting.
| Route | Grade | Wall | Score |
|---|---|---|---|
| Y-12 | V2 | North | 80 |
| Y-14 | V2 | North | 90 |
| Y-17 | V3 | South | 70 |
| Y-19 | V3 | South | 90 |
| Y-21 | V4 | East | |
| Y-23 | V5 | East | |
| Y-25 | V6 | West | 0 |
| Y-27 | V2 | West | 100 |
| Y-29 | V3 | North | 80 |
There are no V7 routes. =COUNTIFS(B2:B10,"V7") returns 0. The same criterion across six functions, measured in Google Sheets:
| Function | Formula | Result |
|---|---|---|
| AVERAGEIFS | =AVERAGEIFS(D2:D10,B2:B10,"V7") | #DIV/0! |
| AVERAGEIF | =AVERAGEIF(B2:B10,"V7",D2:D10) | #DIV/0! |
| SUMIFS | =SUMIFS(D2:D10,B2:B10,"V7") | 0 |
| COUNTIFS | =COUNTIFS(B2:B10,"V7") | 0 |
| MAXIFS | =MAXIFS(D2:D10,B2:B10,"V7") | 0 |
| MINIFS | =MINIFS(D2:D10,B2:B10,"V7") | 0 |
The AVERAGEIFS message is Evaluation of function AVERAGEIFS caused a divide by zero error. AVERAGEIF uses the same wording with AVERAGEIF in the name. A 0 from SUMIFS, COUNTIFS, MAXIFS or MINIFS does not mean that matching scores exist.
The hover uses a red Error heading and includes a Fix button; I did not click Fix. I did not re-check the Excel message on a Mac; treat any Excel wording as unconfirmed. For other zero denominators, see how to fix #DIV/0! errors. If you expected a nonzero sum, see why SUMIF and SUMIFS return zero.
Matching routes don’t always have numeric scores
Change the criterion to V2. =COUNTIFS(B2:B10,"V2") returns 3, and =AVERAGEIFS(D2:D10,B2:B10,"V2") returns 90 — the mean of 80, 90 and 100. V3 averages to 80.
Grades that do have a row, but not a usable score, are a different case:
| Grade | COUNTIFS | AVERAGEIFS | Score in the log |
|---|---|---|---|
| V4 | 1 | #DIV/0! | a genuine blank in D6 |
| V5 | 1 | #DIV/0!, same message | ="" in D7 |
| V6 | 1 | 0 | numeric 0 in D8 |
COUNTIFS counts matching rows, not numeric scores. A recorded zero is a real average. A blank or an empty string is not, and AVERAGEIFS still divides by zero. To count only matching rows that have a number:
=SUMPRODUCT(--(B2:B10="V4"),--ISNUMBER(D2:D10))
That returns 0 for V4 and 1 for V6. ISNUMBER excludes blanks and empty strings without excluding a numeric zero.
Criteria that quietly exclude every row
If COUNTIFS is already 0, AVERAGEIFS will be #DIV/0! for the same reason as V7. Two mismatches that look equal on the grid behaved differently in Sheets.
A text 02 in F2 and a numeric 2 in H2, both displayed as 02 (the number used a 00 format), were treated as a match: =COUNTIFS(F2:F2,H2) returned 1, and =AVERAGEIFS(G2:G2,F2:F2,H2) returned 85. Do not assume a leading-zero lookalike is a mismatch in Google Sheets.
A trailing space is a mismatch. With V2 (length 3) as the criterion, =COUNTIFS(B2:B10,J2) returned 0 与 =AVERAGEIFS(D2:D10,B2:B10,J2) returned #DIV/0! with the same divide-by-zero message.
Wildcards can also empty the set, or do the opposite. =COUNTIFS(B2:B10,"*") returns 9, and =AVERAGEIFS(D2:D10,B2:B10,"*") returns approximately 72.85714286, the mean of the seven numeric scores (80, 90, 70, 90, 0, 100 and 80). The asterisk matches every text grade. A typo such as "W*" matches nothing: COUNTIFS returns 0 and AVERAGEIFS returns #DIV/0!.
Return a label instead of hiding the error
Put V7 in E2. I would test for matching rows before averaging:
=IF(COUNTIFS(B2:B10,E2)=0,"No matching routes",AVERAGEIFS(D2:D10,B2:B10,E2))
That returns No matching routes for V7 and 0 for V6. It leaves the missing-score #DIV/0! visible for V4 and V5, which is what I want when a blank score is a problem to fix.
If missing scores are normal in the log, distinguish those too:
=IF(COUNTIFS(B2:B10,E2)=0,"No matching routes",IF(SUMPRODUCT(--(B2:B10=E2),--ISNUMBER(D2:D10))=0,"No numeric scores",AVERAGEIFS(D2:D10,B2:B10,E2)))
That returns No matching routes for V7, No numeric scores for V4 and V5, 0 for V6, and 90 for V2.
=IFERROR(AVERAGEIFS(D2:D10,B2:B10,E2),"No average") also returns No average for V7, V4 and V5, but it hides unrelated errors such as a broken reference or a mismatched range. See IFERROR vs IFNA for that difference. For a climbing-gym report, I would keep the two labels separate: a grade with no routes is not the same as a grade whose routes have not been scored.
\n