Sub topic 1
Why conditional aggregation: totals, counts, and averages for a subset
Prerequisites
This chapter assumes you can enter and edit formulas in Google Sheets, read range notation such as A2:A100, and use SUM, COUNT, and AVERAGE. You should also know the difference between text, numbers, and dates in cells.
The working model
SUM adds every value in a range. Conditional aggregation adds, counts, or averages only the rows that meet a condition. In a sales sheet with Region in column A and Revenue in column E, you might want the total revenue for the West region alone.
All three functions follow one pattern: a range to test, a criterion to match, and, for SUMIFS and AVERAGEIFS, a range of values to calculate.
COUNTIFS: counting rows that meet a condition
COUNTIFS counts the rows where a condition is true.
=COUNTIFS(A2:A100, "West")The first argument is the range to test, and the second is the criterion. Text matching is not case-sensitive, so "west" also matches.
SUMIFS: summing a range by condition
SUMIFS takes the sum range first, then one or more criteria pairs.
=SUMIFS(E2:E100, A2:A100, "West")The sum range comes first here, which differs from COUNTIFS.
AVERAGEIFS: averaging a range by condition
AVERAGEIFS uses the same shape as SUMIFS, with the average range first.
=AVERAGEIFS(E2:E100, A2:A100, "West")If no row matches, AVERAGEIFS returns #DIV/0!. Section 3 of this tutorial covers how to handle that error.
Exercise
What does =SUMIFS(E2:E100, A2:A100, "East") return?
Show answer
The sum of Revenue in E2:E100 for rows where Region in A2:A100 is "East".