ShareYourGroupShareYourGroupGoogle Sheets

Math and counting

COUNTIF and COUNTIFS functions in Google Sheets

COUNTIF counts the cells that meet one condition; COUNTIFS counts the rows that meet several.

COUNTIF answers "how many?" with a condition: how many passed, how many orders are pending, how many times a name appears. COUNTIFS adds more conditions.

Syntax

=COUNTIF(range, criterion)
=COUNTIFS(criteria_range1, criterion1, [criteria_range2, criterion2], ...)
ArgumentWhat it is
rangeThe cells to look at.
criterionThe condition: a value, a comparison in quotation marks, or a cell.

Examples

Sample sheet: Marks of eight students in three subjects. One Science mark is missing (cell D6 is empty).
ABCDE
1NameClassMathsScienceEnglish
2Asha8A788591
3Ravi8B455260
4Meena8A928879
5Kabir8B334138
6Tara8A6772
7Joy8B889084
8Neha8A546158
9Imran8B787369

How they work

COUNTIF checks each cell of a range against a condition and counts those that pass. COUNTIFS takes pairs of range and condition and counts the rows where all of them hold.

Conditions are written as for SUMIF: text and comparisons in quotation marks, cell references joined on with &, and the wildcards * and ?.

Useful special cases:

Duplicates

Sheets also offers Data, Data clean-up, Remove duplicates for deleting them.

Is a value in another list?

=COUNTIF(Other!A:A, A2)>0 tells whether A2 appears in the other tab. It is the simplest way to compare two lists.

A count for every item, from one formula

Inside ARRAYFORMULA, COUNTIF accepts a list of criteria, as the last example shows. Combined with UNIQUE it makes a frequency table in two cells:

One formula does it all with QUERY: =QUERY(A1:E, "select B, count(A) where B is not null group by B", 1).

COUNTIFS, like SUMIFS, does not expand over a list of criteria.

Counting different values

To count how many different values a range holds, use COUNTUNIQUE, described on the UNIQUE page. COUNTUNIQUEIFS adds conditions.

Counting by a pattern or a calculation

COUNTIF needs a real range and a simple condition. For a test on a calculation, such as the month of a date or a text pattern, count the rows that FILTER returns, or add up a test:

Tick boxes

A column of tick boxes holds TRUE and FALSE. =COUNTIF(D2:D50, TRUE) counts the ticked ones, which makes a quick progress counter for a task list.

Common mistakes

In Excel

COUNTIF and COUNTIFS are the same in Excel. COUNTUNIQUE is not available there.

Related functions

The results on this page were worked out by us from the sample sheet; they were not produced by a script running Google Sheets. If Sheets shows you something different, please tell us.

This is an independent help site. It is not connected with or approved by Google. Google Sheets is a trademark of Google LLC, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.