Sub topic 5
Adding More Conditions: Criteria Pairs and AND Logic
Assume you already know how to enter Google Sheets formulas, use ranges such as A2:A100, and use SUM, COUNT, and AVERAGE. You should also know that text, numbers, and dates are stored differently in cells.
A criteria pair consists of a range and the condition that range must meet. Functions ending in IFS accept several criteria pairs. A row is included only when it satisfies every pair.
How criteria pairs work
Suppose a data table has these columns:
| Column | Meaning |
|---|---|
| A | Region |
| B | Product |
| C | Date |
| D | Units |
| E | Revenue |
To count rows from the West region with at least 10 units, use:
=COUNTIFS(A2:A100, "West", D2:D100, ">=10")The first pair checks the region. The second pair checks the units. Both conditions must be true for the same row.
The same AND logic applies to SUMIFS and AVERAGEIFS. Their first argument is the range being calculated, followed by criteria pairs.
=SUMIFS(E2:E100, A2:A100, "West", D2:D100, ">=10")This adds Revenue only for West rows with at least 10 units.
=AVERAGEIFS(E2:E100, A2:A100, "West", D2:D100, ">=10")This averages Revenue for that same subset.
Adding three or more conditions
Add another range-and-criteria pair for each additional condition. For example, this formula counts West rows with at least 10 units and a nonblank Product cell:
=COUNTIFS(A2:A100, "West", D2:D100, ">=10", B2:B100, "<>")The criteria "<>” means “not equal to,” and with no value after it, it means “not blank.” The quotation marks must be straight quotation marks. The formula without the typographic quote is:
=COUNTIFS(A2:A100, "West", D2:D100, ">=10", B2:B100, "<>")Keep every range aligned
All ranges in an IFS formula should cover the same rows and contain the same number of cells. This is aligned:
=SUMIFS(E2:E100, A2:A100, "West", D2:D100, ">=10")This is unsafe because the ranges end on different rows:
=SUMIFS(E2:E100, A2:A90, "West", D2:D100, ">=10")Misaligned ranges can produce errors or cause conditions to be tested against the wrong records. Start every range on the same row and end every range on the same row.
Check the argument order
The calculation range comes first:
COUNTIFS(criteria_range1, criterion1, ...)SUMIFS(sum_range, criteria_range1, criterion1, ...)AVERAGEIFS(average_range, criteria_range1, criterion1, ...)
A common mistake is placing sum_range after the first criteria pair. In SUMIFS, it must be the first argument.
Exercise
Write a formula that averages Revenue in E2:E100 for East rows where Units in D2:D100 are greater than 20.
Show answer
=AVERAGEIFS(E2:E100, A2:A100, "East", D2:D100, ">20")