HomeGoogle Sheets COUNTIF FunctionFormulas & FunctionsGoogle Sheets COUNTIF Function

Google Sheets COUNTIF Function

The COUNTIF function is a powerful tool designed to tally specific items within a spreadsheet range that meet a single, defined condition. For instance, you can easily calculate how many times a specific salesperson’s name appears, track the number of sales made in a particular city, or determine how many transactions exceeded a certain dollar amount.

For example, consider the following dataset of customer sales:

Countif Google Sheets

This formula counts how many times “John” is found in the range:

=COUNTIF(A2:A11,"John")

This one counts how many times “New York” occurs:

=COUNTIF(B2:B11,"New York")

And this one counts how many sales are over $500:

=COUNTIF(C2:C11,">500")

COUNTIF Function Syntax

=COUNTIF(range, criterion)

It takes 2 arguments:

  • range
  • criterion

The range is the data that you want to count across.

Think of the COUNTIF function as the love child of the IF function and COUNT function.

It’s part of the Math family of functions in Google Sheets.

COUNTIF Function Notes

Text Criterion

Text criterion must be enclosed by quotes:

=COUNTIF(B2:B11,"Apartment")

This formula will count all cells that are equal to the word Apartment.

Numeric Criterion

Exact matches with numeric values do not require quotes:

=COUNTIF(A2:A11,500)

This counts all cells with a value of 500.

Conditional Tests

Logical operators are used to create conditional tests:

  • > greater than
  • >= greater than or equal to
  • < less than
  • <= less than or equal to
  • = equal to
  • <> not equal to

They must be enclosed with double quotes:

=COUNTIF(C2:C11,">500")

This counts all cells with values greater than 500.

Case Insensitive

COUNTIF is case insensitive, so these two formulas will produce the same result:

=COUNTIF(E2:E11,"liam williams")

=COUNTIF(E2:E11,"LIAM WILLIAMS")

Counting Blanks and Non Blanks

To count blank cells in a range, use empty double quotes:

=COUNTIF(F2:F11,"")

To count non-blank cells in a range, use the not-equal logical operator “<>“:

=COUNTIF(F2:F11,"<>")

Reference another cell

The criterion for COUNTIF function can be contained in a different cell and referenced by the COUNTIF formula:

=COUNTIF(E2:E11,B15)

If you want to use a logical operator, then it must still be enclosed in double-quotes. Use an ampersand to combine with the reference cell:

=COUNTIF(D2:D11,">"&B15)

Using Wildcards with COUNTIF

COUNTIF Google Sheets supports three wildcards, *, ?, and ~.

The star * matches zero or more characters.

The question mark ? matches exactly one character.

The tilde ~ is an escape character that lets you search for a * or ?, instead of using them as wildcards.

Let’s see some examples:

Star wildcard

The star wildcard can go in front of, at the end of, or at both ends of your search string. This formula:

=COUNTIF(B2:B11,"*house*")

will count any values containing house, e.g. house, townhouse, big house, house for sale, etc.

Wildcards can be used with reference cells too:

=COUNTIF(E2:E11,"*"&A15&"*")

Question mark wildcard

This formula:

=COUNTIF(A81:A86,"J?n")

will match any string with 3 characters where the first character is “J” and the last character is “n”, e.g. Jon, Jen, and Jan (as well as JXn, JZn, J7n, etc.).

Tilde Escape wildcard

The Tilde ~ is used when you want to search for the wildcard characters themselves e.g. * and ?

=COUNTIF(G2:G11,"Yes~*")

counts all cells containing Yes*, and

=COUNTIF(G2:G11,"Yes~?")

Leave a Reply

Your email address will not be published. Required fields are marked *