Sub topic 1
Why Conditional Aggregation: Totals, Counts, and Averages for a Subset
Prerequisites
This chapter assumes you can already do the following in Google Sheets:
- Enter and edit formulas, starting with
=. - Read range notation such as
A2:A100. - Use
SUM,COUNT, andAVERAGEon a range. - Tell text, numbers, and dates apart in cells. A date is stored as a number but displayed in a date format.
You do not need to know any of the ...IFS functions yet. This chapter explains the problem they solve and shows the shape of every formula the rest of the tutorial builds on.
The problem: a total is rarely the number you need
SUM, COUNT, and AVERAGE work on every cell in a range. Real questions are usually narrower:
- How much revenue came from the West region?
- How many orders were for 10 units or more?
- What is the average sale for widgets in February?
Each question asks for a total, a count, or an average over a subset of rows. This is called conditional aggregation. Aggregation means collapsing many values into one number. Conditional means only the rows that pass a test are included.
Without conditional functions, you have three workarounds, and each has a cost:
| Workaround | Cost |
|---|---|
| Filter the sheet, then read the total from the status bar | The result is not in a cell, so it cannot feed other formulas and it goes stale when data changes |
| Add a helper column such as `=IF(A2="West", E2, 0)`, then sum it | Extra columns, one per question, and more to maintain |
| Add cells by hand, such as `=E2+E4+E6` | Breaks when rows are added, sorted, or edited |
Conditional aggregation functions replace all three. The formula lives in one cell, tests every row each time the sheet recalculates, and updates when the data changes.
The three functions
Google Sheets provides one function for each kind of aggregation:
| Function | Question it answers | Returns |
|---|---|---|
| `COUNTIFS` | How many rows meet the conditions? | A whole number |
| `SUMIFS` | What is the total of a column for those rows? | A number |
| `AVERAGEIFS` | What is the mean of a column for those rows? | A number, or `#DIV/0!` if no row qualifies |
The trailing S stands for "several". Each function accepts one condition or many. All conditions must be true for a row to count, which is AND logic. A later chapter covers this in detail. This chapter only needs you to know that adding conditions makes the subset smaller.
How a conditional function works
Every one of these functions follows the same three steps:
- Look at each row in the data.
- Keep the row only if it passes every condition.
- Count, add, or average the kept rows.
The test in step 2 is identical for all three functions. Only step 3 differs. If you can write the condition for one function, you can write it for the others.
A worked example
The examples in this tutorial use a small sales table. Here it is in rows 2 to 7, with headers in row 1:
| Row | A: Region | B: Product | C: Date | D: Units | E: Revenue |
|---|---|---|---|---|---|
| 2 | West | Widget | 2026-01-05 | 12 | 240 |
| 3 | East | Widget | 2026-01-12 | 8 | 160 |
| 4 | West | Gadget | 2026-02-03 | 5 | 150 |
| 5 | North | Widget | 2026-02-10 | 20 | 400 |
| 6 | West | Widget | 2026-02-15 | 10 | 200 |
| 7 | East | Gadget | 2026-03-01 | 4 | 120 |
The condition in each formula below is "Region equals West". Rows 2, 4, and 6 pass.
Count the West rows:
=COUNTIFS(A2:A7, "West")This returns 3.
Add the Revenue of the West rows:
=SUMIFS(E2:E7, A2:A7, "West")This returns 590, which is 240 + 150 + 200.
Average the Revenue of the West rows:
=AVERAGEIFS(E2:E7, A2:A7, "West")This returns about 196.67, which is 590 divided by 3.
Compare these with =SUM(E2:E7), which returns 1270 for all regions. The only change is the added condition, and the result now describes one region.
Reading the argument order
Each formula has the same pieces. A criteria range is the column you test, and a criterion is the test applied to it. The two always come as a pair.
| Function | Argument order |
|---|---|
| `COUNTIFS` | `criteria_range1, criterion1, [criteria_range2, criterion2, ...]` |
| `SUMIFS` | `sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...]` |
| `AVERAGEIFS` | `average_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...]` |
COUNTIFS has no range of values to total, because it only counts rows. It starts with the first criteria pair. SUMIFS and AVERAGEIFS put the range of values first, followed by the criteria pairs.
What counts as a match
Some behaviors apply to every example in this tutorial:
- Text matching ignores case.
"west","West", and"WEST"all match the same cells. - A criterion such as
"West"is a whole-cell match. A cell containingWest Coastdoes not match unless you use a wildcard, which a later chapter covers. - Cells in the sum or average range that are blank or contain text are skipped, not treated as zero. Skipping matters for averages. A blank cell does not pull the average down.
- Numbers stored as text, such as a Units value pasted in as
"12", can fail to match numeric tests. If a count looks too low, check how the cells are stored.
Why recalculation matters
A conditional formula re-evaluates whenever the source data changes. If you add a West row below row 7 and the ranges cover it, the count, total, and average all update. This is the main advantage over the manual workarounds.
It also creates the main design decision. The ranges must cover the rows you want. This tutorial uses fixed bounds such as A2:A100 for readability. Whole-column ranges such as A:A also work with these functions and automatically include new rows, at the cost of making the formula less obvious about its scope. A later chapter covers sizing rules.
Choosing between the three
Pick the function from the shape of the answer you want:
- Use
COUNTIFSwhen the answer is "how many". - Use
SUMIFSwhen the answer is a total of a numeric column, such as revenue, units, or hours. - Use
AVERAGEIFSwhen the answer is a typical value. It is the only one of the three that can return an error,#DIV/0!, when no row qualifies.COUNTIFSreturns 0 andSUMIFSreturns 0 in the same situation.
You can combine them. Dividing a SUMIFS result by a COUNTIFS result gives the same figure as AVERAGEIFS, which is a useful cross-check when you suspect a formula is wrong.
What comes next
The rest of the tutorial builds on this pattern. You will look at each function in turn, then add more conditions, comparison operators, cell references, dates, wildcards, and blanks. The closing chapters cover OR logic, error handling, and a summary table driven by criteria cells.
Exercise
Using the sales table above, write a formula that returns the total Units for rows where Product is "Widget". Then say what it returns, and which argument must come first.
Show answer
=SUMIFS(D2:D7, B2:B7, "Widget") returns 50, because the Widget rows are 2, 3, 5, and 6 with Units 12, 8, 20, and 10. The sum range (D2:D7, the Units column) must come first, followed by the criteria range (B2:B7) and the criterion ("Widget").
Exercise
For the West rows in the sales table, SUMIFS returns 590 and COUNTIFS returns 3. What does AVERAGEIFS on Revenue return, and what would it return for a region that has no rows, such as "South"?
Show answer
For West it returns 590 / 3, about 196.67. For "South" no row qualifies, so AVERAGEIFS returns #DIV/0!. COUNTIFS would return 0 and SUMIFS would return 0 for the same region.