Going Stellar

Home/Google Sheets reference

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

ArgumentTypeRequiredWhat it does
criteria_rangerangeyesThe cells the criterion is tested against.
criterionanyyesThe condition: a value, a text, or a comparison such as "<8".
average_rangerangenoThe cells to average. If omitted, criteria_range itself is averaged.

Examples

The examples use this table, starting in A1:

RegionProductUnitsPrice
NorthPen102.5
SouthPen42.5
NorthBook312
EastBook812
SouthLamp530
=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.

Sources

  1. AVERAGEIF (Docs Editors Help)

Markdown version · All functions