Sub topic 2
COUNTIFS: Counting Rows That Meet a Condition
This chapter assumes you can enter formulas in Google Sheets, use cell and range notation such as A2:A100, and distinguish text, numbers, and dates. You will use COUNTIFS to count rows that satisfy a condition.
What `COUNTIFS` Does
COUNTIFS counts cells or rows that match one or more conditions. A condition is a rule such as “Region is West” or “Units are at least 10.”
For one condition, the syntax is:
=COUNTIFS(criteria_range, criterion)criteria_rangeis the range to check.criterionis the rule to apply.- The result is the number of matching rows.
Suppose column A contains region names:
| A |
|---|
| Region |
| West |
| East |
| West |
| South |
To count the rows where the region is West, use:
=COUNTIFS(A2:A100, "West")The formula checks each cell in A2:A100 and counts cells whose value matches "West". Text matching is not case-sensitive, so West, WEST, and west match the same criterion.
Read the Formula as a Question
You can read this formula in plain language:
=COUNTIFS(A2:A100, "West")“How many cells in A2:A100 contain West?”
This makes it easier to check a formula. The range and the criterion must describe the same field. Do not use a Revenue range as the criteria range when you mean to check Region.
How Sheets Evaluates the Rows
Sheets compares each position in the criteria range with the criterion.
For example, if A2:A5 contains West, East, West, and South, the result is 2. The header is excluded because the range starts at row 2.
Common Criteria Problems
The criterion must have the correct type and spelling:
- Text criteria usually go in quotation marks:
"West". - A number can be written without quotation marks:
10. - Extra spaces in a cell can prevent a text match.
- A blank cell does not match
"West".
You can also use a cell as the criterion. If G2 contains West, write:
=COUNTIFS(A2:A100, G2)This lets you change G2 without editing the formula. It is useful for a report where a user selects or types a region.
COUNTIFS also supports several criteria pairs. Each additional pair adds another requirement. All requirements must be true for a row to count. The detailed rules for combining conditions appear in a later chapter.
Exercise
Column A contains the values West, East, West, and South in cells A2:A5. What does =COUNTIFS(A2:A5, "West") return?
Show answer
It returns 2 because West appears in two cells.