Menu

AVERAGEIF and AVERAGEIFS in Excel: Average by Condition

=AVERAGEIF(A2:A7,"North",C2:C7) averages the values in C2:C7 on the rows where column A is North. AVERAGEIFS for several conditions, averages that ignore zeros, the #DIV/0! fix, and MAXIFS and MINIFS.

Every sheet on this page is live: change a number or a formula and it recalculates.

=AVERAGEIF(A2:A7,"North",C2:C7) averages the sales in C2:C7 on the rows where column A is North. It works like SUMIF, except that it divides the total by the number of matching rows.

Average by condition
F2
ABCDEF
1RegionProductSalesConditionAverage
2NorthApple120North90
3SouthPear45North, Apple80
4NorthPear110Over 50120
5EastApple55
6SouthApple195
7NorthApple40
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

F2 averages the three North rows, 120, 110 and 40, and shows 90. F3 needs two conditions, North and Apple, so it uses AVERAGEIFS: (120 + 40) / 2 = 80. F4 has no separate average range, so it averages the matching sales themselves.

AVERAGEIF and AVERAGEIFS syntax

=AVERAGEIF(range, criteria, [average_range])
=AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

The argument order is the same trap as SUMIF and SUMIFS: AVERAGEIF puts the range to average last (and lets you leave it out), AVERAGEIFS puts it first. The criteria are written the same way in both: "North", ">50", "<>0", "*apple*", or an operator joined to a cell, ">"&F5. Empty cells and text in the average range are skipped.

Average and ignore zeros

AVERAGE counts a 0 as a value, so two absent students with a score of 0 pull the class average down. Empty cells are different: AVERAGE skips them. =AVERAGEIF(B2:B7,"<>0") skips the zeros too.

Average without zeros
E3
ABCDE
1StudentScoreMethodResult
2Ana80AVERAGE48
3Ben0Ignore zeros80
4Cara90Count of zeros2
5DanCount of numbers5
6Eva70
7Finn0
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

AVERAGE divides 240 by 5, because Dan's empty cell is left out but the two zeros are counted, and shows 48. AVERAGEIF with "<>0" divides 240 by 3 and shows 80. Type 60 into B5 and both change; type 0 into B5 and only AVERAGE moves. To ignore zeros and negative numbers as well, use ">0".

Why AVERAGEIF returns #DIV/0!

When nothing matches, AVERAGEIF has nothing to divide by and returns #DIV/0!. Wrap it in IFERROR to show a dash, a message or an empty cell instead.

No match, and MAXIFS and MINIFS
F2
ABCDEF
1RegionProductSalesFormulaResult
2NorthApple120West average#DIV/0!
3SouthPear45With IFERRORNo sales
4NorthPear110North max120
5EastApple55North min40
6SouthApple195Apple max195
7NorthApple40
#DIV/0! The formula divides by zero or by an empty cell.

There is no West row, so F2 shows #DIV/0! and F3 shows the message. Change A3 to West and both show 45.

MAXIFS and MINIFS

F4 to F6 in the sheet above find the largest and smallest value with a condition. They use the AVERAGEIFS order, the range to search first: =MAXIFS(C2:C7,A2:A7,"North") returns 120 and =MINIFS(C2:C7,A2:A7,"North") returns 40. Unlike AVERAGEIF, they return 0 when nothing matches, not an error.

MAXIFS and MINIFS need Excel 2019 or later, or Microsoft 365. In Excel 2016 and earlier, =MAX(IF(A2:A7="North",C2:C7)) does the same; press Ctrl+Shift+Enter (Cmd+Shift+Enter on a Mac) to enter it in those versions.

Practice: average with two conditions

Your turn: class average without absences
F2
ABCDEF
1StudentClassScoreConditionAverage
2AnaA80Class A, no zeros
3BenB75
4CaraA0
5DanB60
6EvaA90
7FinnB0
8GusA70
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: Average the scores of class A, leaving out the zeros (absent students). Write the formula in F2.

Average of averages: a common mistake

Averaging the averages of groups of different sizes gives the wrong overall average. North has three rows and South two, so each South row counts for more in the average of the two averages than it should.

Average of averages
E4
ABCDE
1RegionSalesFormulaResult
2North120North90
3South45South120
4North110Average of the two105
5South195All rows102
6North40
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

E4 shows 105, E5 the real average of the five rows, 102. When groups differ in size, average the rows themselves with one AVERAGEIFS, or divide a SUMIFS by a COUNTIFS over the same conditions:

=SUMIFS(B2:B6,A2:A6,"North")/COUNTIFS(A2:A6,"North")

A score weighted by credits or by quantity is a different calculation again: that is a weighted average.

Frequently Asked Questions

What is the difference between AVERAGEIF and AVERAGEIFS?

AVERAGEIF takes one condition and puts the average range last: =AVERAGEIF(A2:A7,"North",C2:C7). AVERAGEIFS takes several conditions and puts the average range first: =AVERAGEIFS(C2:C7,A2:A7,"North",B2:B7,"Apple").

How do I average in Excel and ignore zeros?

Use =AVERAGEIF(B2:B7,"<>0"). It averages only the cells that are not 0. Empty cells are already left out by AVERAGE and AVERAGEIF, so only real zeros need the condition.

Why does AVERAGEIF return #DIV/0!?

No cell matched the condition, so Excel divides a sum of 0 by a count of 0. Wrap it to show something else: =IFERROR(AVERAGEIF(A2:A7,"West",C2:C7),"No data").

How do I find the maximum value with a condition?

Use MAXIFS, with the range to search first: =MAXIFS(C2:C7,A2:A7,"North") returns the largest North value. MINIFS works the same for the smallest. Both need Excel 2019 or later, or Microsoft 365.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED