Use AVERAGEIF to average matching rows
AVERAGEIF finds the cells that meet a condition and averages the numbers that go with them. The syntax is:
=AVERAGEIF(range, criteria, [average_range])
- range holds the values you test against the condition.
- criteria is the condition.
- average_range holds the numbers to average. If you leave it out, Excel averages the cells in range.
A regional sales example
This uses the same sample sales table as the SUMIF example:
| A (Region) | B (Sales) |
|---|---|
| East | 1200 |
| West | 850 |
| East | 430 |
| North | 600 |
| East | 275 |
The average for East is:
=AVERAGEIF(A2:A6, "East", B2:B6)
That returns 635, the average of 1200, 430 and 275.
To average only the sales above 400, leave out average_range and use the same range for both parts:
=AVERAGEIF(B2:B6, ">400")
This returns 770, the average of 1200, 850, 430 and 600.
How zeros and blank cells are treated
A zero is a value, so it pulls the average down. A blank cell in the average range is skipped. If a salesperson made no sales in a month, enter 0 when that zero should count, and leave the cell blank only when there is no data yet.
Fix the #DIV/0! error
If no cell meets the condition, AVERAGEIF returns #DIV/0!. The sample table has no row for South, so this formula returns the error:
=AVERAGEIF(A2:A6, "South", B2:B6)
To show text instead, wrap the formula in IFERROR:
=IFERROR(AVERAGEIF(A2:A6, "South", B2:B6), "No sales")
IFERROR hides every error in the formula, not just missing matches, so use it only when an empty result is expected. For more on this error, see how to get rid of #div/0 error in excel.
Average with two conditions
AVERAGEIFS handles several conditions. Like SUMIFS, it takes the average range first:
=AVERAGEIFS(B2:B6, A2:A6, "East", B2:B6, ">300")
This averages the East sales above 300, which are 1200 and 430, for a result of 815.
Related functions
The same range-and-criteria pattern appears in how to use sumif in excel, which totals the matching values rather than averaging them. For totals that depend on several conditions, see sumifs with multiple criteria in excel.