Google Sheets function · Statistical
AVERAGEIF in Google Sheets: syntax and examples
AVERAGEIF tests a range against one criterion and averages the matching cells. If there is no average_range, it averages the tested cells themselves.
Syntax
AVERAGEIF(criteria_range, criterion, [average_range])
Arguments
| Argument | Type | Required | What it does |
|---|---|---|---|
criteria_range | range | yes | The cells the criterion is tested against. |
criterion | any | yes | The condition: a value, a text, or a comparison such as "<8". |
average_range | range | no | The cells to average. If omitted, criteria_range itself is averaged. |
Examples
The examples use this table, starting in A1:
| Region | Product | Units | Price |
| North | Pen | 10 | 2.5 |
| South | Pen | 4 | 2.5 |
| North | Book | 3 | 12 |
| East | Book | 8 | 12 |
| South | Lamp | 5 | 30 |
=AVERAGEIF(A2:A6, "North", C2:C6)Result: 6.5
Average units per North order: (10 + 3) / 2.
Run in a Google Sheet (English US locale) on .
=AVERAGEIF(C2:C6, "<8")Result: 4
Without average_range, the average is taken over the tested cells: 4, 3 and 5.
Run in a Google Sheet (English US locale) on .
=AVERAGEIF(B2:B6, "Book", D2:D6)Result: 12
Average price of Book rows. Criteria and average columns can differ.
Run in a Google Sheet (English US locale) on .
=AVERAGEIF(A2:A6, "South", C2:C6)Result: 4.5
A result with a decimal part: (4 + 5) / 2.
Run in a Google Sheet (English US locale) on .
=IFERROR(AVERAGEIF(A2:A6, "West", C2:C6), 0)Result: 0
No row matches West, so AVERAGEIF alone would fail. IFERROR gives 0 instead.
Run in a Google Sheet (English US locale) on .
Common errors
- When no row matches, the result is #DIV/0!, because there is nothing to average. Wrap the call in IFERROR if that can happen.
- Leaving out average_range on a text column does not average anything. AVERAGEIF(B2:B6, "Pen") returns #DIV/0! since the cells it would average are words.
- One condition only. Use AVERAGEIFS when you need two or more.
Compared with Excel
Same syntax in Excel. Excel and Sheets both have AVERAGEIFS for several conditions.