The COUNTIF function in Google Sheets is used to count the items across a range of data depending on a conditional test. The COUNTIF function only counts items when the condition is true.
SYNTAX: =COUNTIF(range, criterion)
range: The data that you want to count.
criterion: The condition that must be met for a cell to be counted.
The best way to look at this function is through a specific example. In the data below, we want to answer the question: How many times did the person purchase groceries?
This data set is relatively small so we could rather efficiently count the number of times that the person purchased groceries. While this is true, we will use it as an example of how the COUNTIF function works and you can see how it would apply to larger and less organized data sets.
We want to tell the function to count the number of times that the word Groceries appears in column A. But first, we need to set up a space to do this work.
It is best practice to label work clearly in sheets so that you or anyone else that will be using or reviewing the data at a later date can easily understand the steps that you took and the logic that you used.
To make your thinking clear:
Label column C: # of Occurences
In C2, type Groceries
To use the COUNTIF function to find the number of times the person purchased Groceries:
Click in cell D2
Type =COUNTIF(
The first statement is the range that you want to look for your criterion. In this case, that is the different categories in column A. So you should type A2:A23. You always separate statements by commas.
The next part of the statement is your criterion or what you are looking for. In this case, you want to find all the times the person paid for Groceries. You have to options:
Type: "Groceries"
Type: C2 -> you can use this cell because when you set up your clear thinking, you typed "Groceries" in cell C2. I always recommend using a cell rather than typing words because it reduces error points and makes your formulas more dynamic.
Hit ENTER
Use this link to see additional examples and uses for the COUNTIF function.