Sub topic 5
AVERAGEIFS: averaging matching values
This chapter covers AVERAGEIFS, the function that returns the mean of the values that meet one or more conditions. It builds directly on SUMIFS, so the argument order will look familiar.
Prerequisites
This chapter assumes you can do the following:
- Enter and copy formulas in Excel.
- Tell relative references from absolute references (
$D$2). - Use SUM, COUNT, and AVERAGE.
- Read data laid out in rows and columns with headers.
- Read a SUMIFS formula, including its range and criteria pairs.
All examples use the sample sales layout below. Headers are in row 1 and data runs from row 2 down to row 100.
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 GiftWhat AVERAGEIFS does
AVERAGE gives the mean of every number in a range. AVERAGEIFS gives the mean of only the numbers whose rows pass your tests. A "mean" is the sum of the values divided by how many values there are. AVERAGEIFS does both steps for the matching rows only.
The syntax is:
AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)The first argument is the range to average. The remaining arguments come in pairs. Each pair has a range to test and a condition to test it with. This is the same layout as SUMIFS. COUNTIFS has no first argument because it counts rows instead of averaging a column.
Here is the mean Amount for West rows:
=AVERAGEIFS(D2:D100, B2:B100, "West")With the four sample rows above, the West rows are 1200 and 310, so the result is 755. The East and North rows are skipped entirely.
How it works internally
Excel evaluates AVERAGEIFS in three steps:
- It goes through each row position and checks every criteria pair against the cell at that position.
- It keeps a row only if all of the pairs are true. Conditions are combined with AND.
- It averages the cells in the average range at the kept positions, then divides the sum by the number of those cells.
The process matches rows by position. The third cell of the first criteria range is paired with the third cell of the average range. This is why all the ranges must have the same number of rows and columns. A mismatch returns #VALUE!.
Which cells are ignored
The average range can contain cells that are not usable numbers. AVERAGEIFS treats them as follows:
| Content of the average-range cell | Effect on the result |
|---|---|
| A number | Included in the sum and the count |
| A blank cell | Skipped, even if the criteria match |
| Text, including numbers stored as text | Skipped |
| `TRUE` or `FALSE` | Skipped |
| An error such as `#N/A` | Causes the same error in the result, if that row matches |
The "skipped" behavior has a practical consequence. A blank Amount in a matching row does not count as zero. It is left out of both the sum and the count, so the mean is higher than it would be if you treated the blank as zero. If blanks really mean zero in your data, fill them with 0 first.
Text-formatted numbers are a common trap. A cell showing 1200 that is stored as text is skipped silently, and the result is wrong without any error. A left-aligned number is often the clue.
Using several conditions
Add more range and criteria pairs to narrow the rows. Every pair must be true for a row to count. This formula averages the Amount for West rows where the product is a Laptop:
=AVERAGEIFS(D2:D100, B2:B100, "West", C2:C100, "Laptop")Criteria can use comparison operators. An operator is written inside a quoted string. To bring a cell value into the condition, join it with &. If G1 holds a minimum amount, this averages West rows at or above that amount:
=AVERAGEIFS(D2:D100, B2:B100, "West", D2:D100, ">=" & G1)Note that D2:D100 appears twice. Once it is the range to average, and once it is a range to test. This is allowed, and it is a common pattern for "the average of the large sales".
When no row matches: #DIV/0!
If no row passes every test, the count is zero. Dividing by zero is not possible, so AVERAGEIFS returns #DIV/0!. SUMIFS and COUNTIFS do not do this. They return 0 for no match, because 0 is a sensible sum and count.
The same error also appears when rows match but every matching average cell is blank or text. The count of usable numbers is still zero.
Wrap the formula in IFERROR to show readable text:
=IFERROR(AVERAGEIFS(D2:D100, B2:B100, "South"), "No sales")The sample data has no South rows, so this shows "No sales".
If you want to hide only the no-match case, test for it directly with COUNTIFS:
=IF(COUNTIFS(B2:B100, "South") = 0, "No sales", AVERAGEIFS(D2:D100, B2:B100, "South"))This version lets real errors show through. It is longer, and you must repeat the same criteria in both functions, so a change in one place has to be made in the other.
Criteria behave like SUMIFS and COUNTIFS
Everything about criteria carries over from the other two functions:
- Matching text ignores letter case, so
"west"matchesWest. - Wildcards work in text criteria.
*matches any run of characters and?matches one character. - An empty string
""matches blank cells, and"<>"matches non-blank cells. - Dates are compared as numbers, so build them with DATE rather than typing text.
This formula averages the Amount for all products starting with "Mon" in January 2025:
=AVERAGEIFS(D2:D100, C2:C100, "Mon*", A2:A100, ">=" & DATE(2025,1,1), A2:A100, "<" & DATE(2025,2,1))On the sample rows, only the East Monitor row on 2025-01-09 qualifies, so the result is 300.
Weighted and unweighted means
AVERAGEIFS gives each matching row the same weight. This is correct for "the average sale" but not for every question. If you need a weighted average, such as the average price weighted by quantity, AVERAGEIFS gives the wrong answer. Divide two SUMIFS results instead, or use SUMPRODUCT, which a later chapter covers.
Common mistakes
- Averaging the wrong column. The first argument is the column to average, not a column to test. Putting the criteria range first averages the wrong thing, or fails if that column holds text.
- Mismatched sizes.
D2:D100withB2:B90returns#VALUE!. - Expecting blanks to count as zero. They are skipped. The mean covers only the cells that hold numbers.
- Numbers stored as text. They are skipped silently. Convert them to real numbers.
- Using OR inside one function. Two criteria on the same field, such as
"West"and"East", find no rows, because a region cannot be both. Handle OR logic in a later chapter.
An average of averages is also a trap. Averaging the region means gives a different number than the overall mean when regions have different row counts. Compute the overall figure directly with AVERAGEIFS or from totals.
Exercise
Using the sample data, write a formula that returns the mean Amount for rows where Region is "West" and the Amount is below 1000. Then say what it returns for the four sample rows, and what it returns if the only West row left is 1200.
Show answer
=AVERAGEIFS(D2:D100, B2:B100, "West", D2:D100, "<1000"). For the four sample rows, the West rows are 1200 and 310. Only 310 is below 1000, so the result is 310. If the only West row is 1200, no row passes both tests, the count is zero, and the formula returns #DIV/0!. Wrap it in IFERROR (for example IFERROR(..., "None")) to show text instead.
Exercise
A matching row has an empty Amount cell. Does AVERAGEIFS treat it as 0? Say how this changes the result compared with filling the cell with 0.
Show answer
No. A blank average-range cell is skipped, so it is left out of both the sum and the count. The mean is therefore higher than it would be if the cell held 0, because a 0 would add one to the count without adding to the sum.