AVERAGEIF Function for Conditional Averages in Google Sheets

The AVERAGEIF function in Google Sheets allows you to calculate averages based on a specific condition applied to a row or column. This guide explains the syntax, provides examples, and offers practical tips.

For multiple conditions, you can use AVERAGEIFS, which supports more than one criterion. Let’s dive into the syntax and usage of the AVERAGEIF function in Google Sheets.

AVERAGEIF Function: Syntax and Arguments

Syntax:

AVERAGEIF(criteria_range, criterion, [average_range])

Arguments:

  • criteria_range: The range to evaluate against the condition.
  • criterion: The condition or pattern applied to criteria_range.
  • average_range: The range of values to average. If omitted, criteria_range is used.

Examples

  1. Average of values in B2:B100 where A2:A100 contains “Apple”:
    =AVERAGEIF(A2:A100, "Apple", B2:B100)
  2. Average of values in B2:B100 where values are greater than 200:
    =AVERAGEIF(B2:B100, ">200")

Note: The AVERAGEIF function is case-insensitive.

Find Average Based on a Condition in Google Sheets

Here are some common use cases:

1. Using a Number as a Criterion

In the following example, A2:11, B2:B11, and C2:C11 contain student names, their class, and their marks, respectively.

To calculate the average marks scored by students in Class 5, use this formula:

=AVERAGEIF(B2:B11, 5, C2:C11)
Using a number as a criterion in the AVERAGEIF function in Google Sheets

You can also use double quotes for the criterion, such as "5". Google Sheets treats both 5 and "5" as equivalent when the criterion is a number.

For comparison operators (e.g., greater than or less than), numbers must be enclosed in quotes:

=AVERAGEIF(B2:B11, ">5", C2:C11)

2. Using Dates as a Criterion

Dates can be tricky due to formatting differences. To ensure accuracy in the conditional average calculation, use the DATE function or the ISO 8601 format (YYYY-MM-DD).

Sample Data: A2:A11 contains sales dates, and B2:B11 contains quantities sold.

  • Average quantity sold on March 19, 2018:
    =AVERAGEIF(A2:A11, DATE(2018, 3, 19), B2:B11) Or: =AVERAGEIF(A2:A11, "2018-03-19", B2:B11)
  • Average quantity sold on or after March 19, 2018:
    =AVERAGEIF(A2:A11, ">=" & DATE(2018, 3, 19), B2:B11)
  • The average for today’s date:
    =AVERAGEIF(A2:A11, TODAY(), B2:B11)
Using date criteria in the AVERAGEIF function in Google Sheets

3. Finding the Average of Non-Blank Cells

To calculate the average of non-blank cells, use the <> operator (logical NOT):

=AVERAGEIF(A2:A11, "<>", B2:B11)
Finding the average of non-blank cells using AVERAGEIF in Google Sheets

4. Using Wildcards with AVERAGEIF Function

Wildcard characters (*, ?, ~) enhance flexibility with text-based conditions, and this also applies to the AVERAGEIF function:

  • Asterisk (*): Matches any number of characters.
    =AVERAGEIF(B2:B6, "north*", C2:C6) This matches text like “north”, “northern”, or “northwest”.
  • Question Mark (?): Matches any single character.
    =AVERAGEIF(B2:B6, "n?rth", C2:C6)
  • Tilde (~): Escapes special meanings of * and ?.
    =AVERAGEIF(B2:B6, "north~*", C2:C6) Matches the literal text “north*”.

5. Case-Sensitive Matches in the AVERAGEIF Function

To perform a case-sensitive match, use the EXACT function with AVERAGEIF. Since EXACT is not an array function, wrap it with ARRAYFORMULA:

  • Average for case-sensitive match of “Apple”:
    =ARRAYFORMULA(AVERAGEIF(EXACT(A2:A7, "Apple"), TRUE, B2:B7))

Here:

  • EXACT(A2:A7, "Apple") returns TRUE or FALSE for each cell.
  • TRUE is used as the criterion.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

Time Sequences in Excel by Minute, Hour, or Second Increments

Creating time sequences, whether by hour, minute, or second increments in Excel, can be...

Finding Most Frequent Text in Excel with Dynamic Array Formulas

Looking to identify the most frequently occurring text in Excel? You can do this...

Hierarchical Numbering Sequences in Excel

Creating hierarchical numbering sequences in an Excel spreadsheet can significantly improve the way you...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

6 COMMENTS

    • Hi, Stephen Doyle,

      I’m in the dark 🙁

      If you want to find the average of the numbers in the above cells excluding zeros, then try this.

      =AVERAGEIF({D2,F2,H2,J2,L2,N2,P2,R2},"<>0")

      Looking for something else? Please explain.

  1. Please provide the formula if time function is used and if criteria are more than one and the criteria values of the range are time values.

    e.g.

    AVERAGEIF(B670:B780,{"NKCR","OKSR","SGRL","KRSL","MDMD","JRGR","BRRB","GPCK","SCDG"},H670:H780)

    I tried using arrayformula like below:

    Arrayformula(AVERAGEIF(B670:B780,{"NKCR","OKSR","SGRL","KRSL","MDMD","JRGR","BRRB","GPCK","SCDG"},H670:H780)

    but this returned an average of only the first criteria “NKCR”.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.