Conditional totals · About 6 minutes
Average matching rows with AVERAGEIF
AVERAGEIF works like SUMIF, but finds the average instead of the total. =AVERAGEIF( reads as "look down B2 to B7 for A, and average the matching Maths marks".
AVERAGEIFS handles more than one condition. Like SUMIFS, the range to average goes first, then pairs of "where to look, what to look for".
If no row matches, there is nothing to average, so the cell shows #DIV.
Part of Plus
Free during our founding launch: sign in to unlock this lesson's exercises, the timed practice sets and the rest of Plus. The free lessons stay free, with no account needed.
What AVERAGEIF and AVERAGEIFS does
AVERAGEIF finds the average of only the rows that pass one test. AVERAGEIFS does the same with two or more tests, and a row counts only when it passes all of them.
A common use is an average without zeros: days with no sales, or tests not yet taken, can pull an average down. A test like "<>0", meaning "not 0", leaves them out.
How to write AVERAGEIF and AVERAGEIFS
=AVERAGEIF(
- range
- The cells to test.
- criteria
- The test each cell must pass, like
"<>0"or"Day". - average_range
- The numbers to average on the rows that pass. Leave it out to average the tested cells themselves.
=AVERAGEIFS(
- average_range
- The numbers to average. Like SUMIFS, this comes first.
- criteria_range1, criteria1, ...
- Pairs of "where to look, what to look for".
AVERAGEIF and AVERAGEIFS worked example
A stall logs units sold each day, with 0 on closed days. In B8, find the average of the open days only.
| A | B | |
|---|---|---|
| 1 | Day | Units |
| 2 | Mon | 12 |
| 3 | Tue | 0 |
| 4 | Wed | 18 |
| 5 | Thu | 0 |
| 6 | Fri | 15 |
| 7 | ||
| 8 | No zeros | 15 |
=AVERAGEIF( B2:B6, "<>0")Average the units in B2 to B6 that are not 0: (12 + 18 + 15) / 3 = 15. A plain AVERAGE would give 9.Common AVERAGEIF and AVERAGEIFS mistakes
The cell shows #DIV/0!
No row passed the test, so there is nothing to average. Check the test matches the data, or wrap the formula in IFERROR to show a message.
The average is lower than expected
Zeros are being counted. Plain AVERAGE includes them; use AVERAGEIF with "<>0" to leave them out. Empty cells are already skipped.
AVERAGEIFS averages the wrong column
Put the range to average first, then the pairs. AVERAGEIF puts it last, so the order is easy to mix up.
AVERAGEIF, AVERAGEIFS or AVERAGE?
Use AVERAGE when every number counts. Use AVERAGEIF for one test, and AVERAGEIFS for two or more, like one shift and one month.
Both are in Excel 2007 and later and in Google Sheets. If you need the total or the count of those rows instead, the same tests work in SUMIFS and COUNTIFS.
Questions people ask
What is the difference between AVERAGEIF and AVERAGEIFS?
AVERAGEIF takes one condition, with the range to average last. AVERAGEIFS takes one or more, with the range to average first.
Why does AVERAGEIF return #DIV/0!?
No rows matched, so there is nothing to average. Check the condition, or wrap the formula in IFERROR.
How do I average only numbers above zero?
Use =AVERAGEIF(.
Does AVERAGEIF ignore blank cells?
Yes. Empty cells in the range being averaged are skipped, not counted as 0.