COUNTIF Function in☝️ Google Sheets Explained (Definition, Syntax, How to Use It, Examples)

This guide covers everything you need to know about the Google Sheets COUNTIF function, including its definition, syntax, use cases, and how to use it.

What is the COUNTIF Function? How Does It Work?

The COUNTIF function in Google Sheets returns a conditional count across a range of cells. Essentially, it allows you to count the number of cells that meet a specified condition within a selected range.

The primary purpose of the COUNTIF function is to evaluate a set of data according to a certain condition and then provide a count of cells that meet that condition. For instance, if you have a list of salespeople and their respective sales, you could use the COUNTIF function to identify the number of salespeople who managed to make sales above a certain figure.

The COUNTIF function is composed of two elements: the range and the criterion. The range refers to the group of cells you want the function to analyze, while the criterion is the specific condition that the function should look for within the range.

The criterion can be either a string or a number. In the case of a string criterion, it must be enclosed in quotation marks. You can use wildcards, like the question mark (?) to represent any single character and the asterisk (*) to signify zero or more contiguous characters. To match an actual question mark or asterisk, you would use the tilde (~) character before them.

On the other hand, when the range contains numbers, the criterion can be a string, a number, or a number with an operator. These operators can be ‘equal to’ (=), ‘greater than’ (>), ‘greater than or equal to’ (>=), ‘less than’ (<), or ‘less than or equal to’ (<=).

However, it’s important to note that the COUNTIF function only performs conditional counts with a single criterion. If you need to use multiple criteria, you should use the COUNTIFS function or the database functions DCOUNT or DCOUNTA. The COUNTIF function is not case sensitive, meaning it will not differentiate between lowercase and uppercase letters when evaluating text.

COUNTIF Syntax

The syntax and arguments for the function are as follows:

COUNTIF(range, criterion)

  • range: This is the range of cells that you want to test against the criterion. It can include numbers, text, or both.
  • criterion: This is the condition that you want to test the range against. It can be a number, text, or a logical expression.

Here are some important notes about these arguments and their usage:

  • If the range argument contains text that you want to check against, the criterion must be a string. The criterion can contain wildcard characters such as “?” to match any single character or “*” to match any sequence of characters. If you want to match an actual question mark or asterisk, you can prefix the character with the tilde (~) character. For example, “~?” and “~*”. Remember to enclose your string criterion in quotation marks.
  • If the range argument contains numbers, the criterion can be either a string or a number. If you provide a number, the function will check each cell in the range for equality with the criterion. Alternatively, the criterion can be a string containing a number, which will also check for equality. You can also use a number prefixed with any of the following operators: =, >, >=, <, <=. These operators will check whether each cell in the range is equal to, greater than, greater than or equal to, less than, or less than or equal to the criterion value, respectively.
  • Keep in mind that the COUNTIF function can only perform conditional counts with a single criterion. If you need to use multiple criteria, you should use the COUNTIFS function or the database functions DCOUNT or DCOUNTA.
  • The COUNTIF function is not case sensitive. This means that it treats lowercase and uppercase letters as the same. For example, COUNTIF(A1:A10,”Paid”) and COUNTIF(A1:A10,”PAID”) will return the same result.

Examples of How to Use the COUNTIF Function

Here are some practical examples of how you can use the COUNTIF function in Google Sheets.

Example #1: Counting Specific Text Entries

Let’s suppose you have a list of names in column A, and you want to count how many times the name “John” appears. You would use the COUNTIF function as follows:

=COUNTIF(A2:A100, “John”)

In this example, A2:A100 is the range of cells you want to check, and “John” is the criteria. Google Sheets will count the number of cells in the range A2:A100 that contain the word “John”.

Example #2: Counting Numbers Greater Than a Certain Value

Suppose you have a column of numbers (column B), and you want to count how many are greater than 50. You would use the COUNTIF function as follows:

=COUNTIF(B2:B100, “>50”)

Here, B2:B100 is the range of cells you want to check, and “>50” is the criteria. Google Sheets will count the number of cells in the range B2:B100 that contain a number greater than 50.

Example #3: Counting Cells That Meet Multiple Criteria

Let’s say you have a column of grades (column C), and you want to count how many are either “A” or “B”. You would use the COUNTIF function twice and add the results together:

=COUNTIF(C2:C100, “A”) + COUNTIF(C2:C100, “B”)

In this example, C2:C100 is the range of cells you want to check, and “A” and “B” are the criteria. Google Sheets will count the number of cells in the range C2:C100 that contain either “A” or “B” and then add these counts together.

Example #4: Counting Cells That Contain Specific Text

Suppose you have a column of sentences (column D), and you want to count how many contain the word “Google”. You would use the COUNTIF function as follows:

=COUNTIF(D2:D100, “*Google*”)

In this example, D2:D100 is the range of cells you want to check, and “*Google*” is the criteria. The asterisks (*) are wildcards that represent any number of characters. So, Google Sheets will count the number of cells in the range D2:D100 that contain the word “Google” anywhere within them.

COUNTIF: Common Mistakes & Problems

When using the COUNTIF function in Google Sheets, even experienced users can encounter some common mistakes and problems. Being aware of these potential issues can help you troubleshoot and correct your formulas more effectively:

  • Incorrectly formatted criteria: The criteria in your COUNTIF function should be expressed as a text string. For instance, if you’re trying to count cells that contain a number greater than 100, your criteria should be “>100”, not just >100.
  • COUNTIF vs. COUNTIFS: If you need to apply multiple criteria to the same range, you should use the COUNTIFS function, not COUNTIF. The COUNTIF function can only handle one criterion per range.
  • Ignoring case sensitivity: The COUNTIF function isn’t case-sensitive. If you need to count cells based on case-sensitive criteria, you’ll have to use a different method, such as an array formula with the EXACT function.
  • Misunderstanding of wildcard characters: The COUNTIF function supports the use of wildcard characters, but they may not behave as you expect. The asterisk (*) represents any sequence of characters, while the question mark (?) represents any single character. If you need to count cells that actually contain an asterisk or question mark, you’ll have to precede the character with a tilde (~).
  • Failure to update ranges: If you add or remove rows or columns within your range, you’ll need to update your COUNTIF function to reflect the new range. The function doesn’t automatically adjust to changes in your data.
  • Incorrect use of cell references: If you’re using a cell reference as your criteria, you need to concatenate it with the comparison operator using an ampersand (&). For instance, to count cells in A1:A10 that are greater than the value in B1, your criteria should be “>”&B1, not “>B1”.
  • Inaccurate criteria for dates and times: When using dates or times as criteria, they should be formatted as date or time serial numbers, not as text. For example, to count cells that contain a date later than January 1, 2021, your criteria should be “>44197”, not “>01/01/2021”.

Why Is COUNTIF Not Working? Troubleshooting Common Errors

If you’re trying to use the COUNTIF function in Google Sheets, and it’s not working as expected, it may be due to several common errors. These can be caused by various factors, such as incorrect references, incorrect syntax, or data types not matching. This section will guide you through some of these common errors, their causes, and solutions.

#VALUE! Error

Cause: This error occurs when the range or criterion in the COUNTIF function is not valid.

Solution: Make sure that the range you’re referencing exists and the criterion you’re using is valid. The criterion should be a text string, number, or expression representing the condition you’re testing.

#REF! Error

Cause: This error happens when the range in the COUNTIF function refers to a cell that is not valid.

Solution: Check your formula to ensure that all cell references are valid and that they reference cells within the current sheet or another sheet that exists.

#N/A Error

Cause: This error is caused when the criterion in the COUNTIF function refers to a cell that does not exist or cannot be found.

Solution: Ensure that the cell you’re referring to in your criterion exists and can be found. If you’re referencing a cell from another sheet, make sure the sheet name and cell reference are correct.

#DIV/0! Error

Cause: This error is because you’re trying to divide a number by zero in your COUNTIF function, which is not possible in mathematics.

Solution: Check your COUNTIF function to make sure you’re not dividing by zero. If you’re using a cell reference as the divisor, ensure that this cell contains a number other than zero.

#NAME? Error

Cause: This error occurs when Google Sheets does not recognize the text in your formula. This could be because the function’s name is spelled incorrectly, or it’s a function that Google Sheets does not support.

Solution: Ensure you’ve spelled the COUNTIF function correctly in your formula. If you’re using another function within your COUNTIF function, ensure it’s a function that Google Sheets supports.

#NUM! Error

Cause: This error is caused when you’re using a number in your COUNTIF function that’s not valid.

Solution: Check your COUNTIF function to ensure all numbers used are valid. This could mean ensuring that a number is within the accepted range or the correct data type.

By identifying the type of error you’re encountering and understanding its cause, you can easily find a solution and fix your COUNTIF function in Google Sheets.

For more details on the COUNTIF function, check out the official documentation at the Google Docs Editors Help Center.

More Google Sheets Tutorials
More Microsoft Excel Tutorials
Share This Post
Daniel Smith
Daniel Smith
Daniel Smith is automation consultant with a passion for technology, data, AI, and machine learning.