Count what matches with COUNTIF and COUNTIFS
Counting and statistics8 min
Builds on Total by one condition with SUMIF.
Every Monday, a call center manager in Illinois reports how many of last week's calls ran over the time limit, and how many of those were billing calls. The limit is reviewed every quarter, so the counts have to follow it.
How it works
COUNTIF(range, criteria) counts the cells in a range that pass one test. Picture it going down the column and checking off every cell that passes, then returning how many it checked off. The tests are written as in SUMIF: "Late", ">500", a cell, or ">"&G1. COUNTIFS(range1, criteria1, range2, criteria2, …) counts the rows that pass every test, one pair per column, like SUMIFS with nothing to add.
Two more kinds of test are handy for counting:
| Row | A | B |
|---|---|---|
| 1 | Test | Counts the cells that |
| 2 | "<>Closed" | aren't Closed, empty cells included |
| 3 | "<>" | aren't empty |
| 4 | "EL-*" | start with EL-, because * stands for any characters |
| 5 | "*urgent*" | contain urgent anywhere |
Example
Call lengths, in minutes, are in D2:D11, the type of each call is in C2:C11, and the team's limit, 15, is in G1.
=COUNTIF(D2:D11,">"&G1)=COUNTIFS(C2:C11,"Billing",D2:D11,">"&G1)With calls of 12, 18, 15, 9, 22, 15, 31, 7, 16 and 14 minutes, the first returns 4: the two calls of exactly 15 minutes aren't over the limit. Two of the four are billing calls, so the second returns 2.
Common mistakes
=COUNTIF(D2:D11,">G1")returns 0. Inside quotation marks, G1 is just text: join the comparison to the cell with&.=COUNTIF(C2:C11,"Billing")+COUNTIF(D2:D11,">"&G1)counts every billing call and every long call, and long billing calls twice. COUNTIFS counts only the rows that pass both tests."EL-"without a*counts only the cells that are exactly EL-. To match the start, write"EL-*"."<>Closed"counts empty cells too, so a range that runs past the end of the list counts the blank rows. End the range on the last row of data.
In short
=COUNTIF(range, criteria)counts what passes one test, and=COUNTIFS(range1, test1, range2, test2)counts the rows that pass every test."<>x"means not equal to x, and"<>"means not empty.*matches any characters:"EL-*"finds everything that starts with EL-.- Keep a limit in a cell and join it with
&, and lock the ranges with$before you fill a count down a summary.
Practice
4 exercises · free with an account