Google Sheets COUNTIF is one of the easiest functions to learn and one of the handiest to use.

It's time to pick up some knowledge on how COUNTIF is used in Google Spreadsheet and learn why this function makes a true Google Spreadsheet companion.

## What is COUNTIF function in Google Sheets?

This short helper allows us to count how many times a certain value appears within a specified data range.

## COUNTIF syntax in Google Sheets

The syntax of our function and its arguments are as follows:

**range**- a range of cells where we want to count a certain value. Required.**criterion**or searching criterion - a value to find and count across the data range indicated in the first argument. Required.

## Google Spreadsheet COUNTIF in practice

It may seem that COUNTIF is so simple that it doesn't even count as a function (pun intended), but in truth its potential is quite impressive. Its searching criteria alone is enough to earn such a description.

The thing is that we can decide to look for not only concrete values, but also those that meet certain criteria.

It's high time to try and build a formula together.

### Google Spreadsheet COUNTIF for text and numbers (exact match)

Let's suppose your company sells various types of chocolate in several consumer regions and works with many clients.

This is how your sales data look like in Google Sheets:

Let's begin from the basics.

We need to count the number of sales in the "West" region. Place the cursor in C3 and enter the equality sign (=). Google Sheet immediately understands that we are going to enter a formula. As soon as you type the letter "C", it will prompt us to choose a function that begins with this letter. And we select "COUNTIF".

*The first argument* of COUNTIF is represented by **the following range**: D4:B74. By the way, you don't have to enter the range manually - mouse selection is enough. Then enter a comma (,) and specify the second argument - searching criteria.

*The second argument* is a value that we're going to look for across the selected range. In our case it's going to be **the text** - "Milk Chocolate". Remember to finish the function with a closing bracket ")" and press "Enter".

Also, don't forget to enter double quotes ("") when using text values.

Our final formula looks as follows:

`=COUNTIF(D6:D16,"Milk Chocolate")`

As a result, we get three sales of this type of chocolate.

**Note.**COUNTIF function works with a single cell or neighboring columns. In other words, you can't indicate a few separate cells or columns and rows. Please see the examples below.

Incorrect formulas:

`=COUNTIF(C6:C16, D6:D16,"Milk Chocolate")`

`=COUNTIF(D6, D8, D10, D12, D14,"Milk Chocolate")`

Correct usage:

`=COUNTIF(C6:D16,"Milk Chocolate")`

`=COUNTIF(D6,"Milk Chocolate") + COUNTIF(D8,"Milk Chocolate") + COUNTIF(D10,"Milk Chocolate") + COUNTIF(D12,"Milk Chocolate") + COUNTIF(D14,"Milk Chocolate")`

You may have noticed that it's not really convenient to set the searching criteria in the formula - you have to edit it every time. The better decision would be to write the criteria down other Google Sheets cell and reference that cell in the formula.

Let's count the number of occurred sales in the "West" region using the cell reference in COUNTIF. We'll get the following formula:

`=COUNTIF(C6:C16,A3)`

The function uses the content of A3 (the text value "West") in its calculations. As you can see, it's a lot easier now to edit the formula and its searching criteria.

Of course, we can do the same thing **with numerical values**. We can count the number of occurrences of the number "125" by indicating the number itself as a second argument:

`=COUNTIF(E7:E17,125)`

or by replacing it with a cell reference:

`=COUNTIF(E7:E17,A3)`

### Google Spreadsheet COUNTIF function and wildcard characters (partial match)

What is great about COUNTIF is that it can count whole cells as well as **parts of the cell's contents**. For that purpose, we use *wildcard characters*: "?", "*".

For instance, to count the sales in some particular region we can use only the part of its name: enter "?est" into B3. A **question mark** (?) replaces *one character*. We are going to look for the 4-letter words *ending with "est"*, including spaces.

Use the following COUNTIF formula in B3:

`=COUNTIF(C7:C17,A3)`

As you already know, the formula can easily take the next form:

`=COUNTIF(C7:C17, "?est")`

And we can see 5 sales in the "West" region.

Now let us employ the B4 cell for another formula:

`=COUNTIF(C7:C17,A4)`

What is more, we'll change the criteria to "??st" in A4. It means that now we are going to look for 4-letter words *ending with "st"*. Since in this case two regions ("West" and "East") satisfy our criteria, we will see nine sales:

Similarly, we can count the number of sales of the goods using an **asterisk** (*). This symbol replaces not just one, but *any number of characters*:

*"*Chocolate"* criteria counts all the products ending with "Chocolate".

*"Chocolate*"* criteria counts all the products starting with "Chocolate".

And, as you may guess, if we enter *"*Chocolate*"*, we're going to look for all the products that contain the word "Chocolate".

**Note.**If you need to count the number of words that contain an asterisk (*) and a question mark (?), then use

**tilde sign**(~) before those characters. In this case, COUNTIF will treat them as simple signs rather than searching characters. For example, if we want to look for the values that contain "?", the formula will be:

`=COUNTIF(D7:D15,"*~?*")`

### COUNTIF Google Sheets for less than, greater than or equal to

The COUNTIF function is able to count not only how many times some number appears, but also how many of the numbers are *greater than/less than/equal to/not equal to* another specified number.

For that purpose, we use corresponding mathematical operators: "=", ">", "<", ">=", "<=", "<>".

Check out the table below to see how it works:

Criteria | Formula example | Description |

The number is greater than | `=COUNTIF(F9:F19,">100")` |
Count cells where values are greater than 100. |

The number is less than | `=COUNTIF(F9:F19,"<100")` |
Count cells where values are less than 100. |

The number equals to | `=COUNTIF(F9:F19,"=100")` |
Count cells where values equal to 100. |

The number is not equal to | `=COUNTIF(F9:F19,"<>100")` |
Count cells where values are not equal to 100. |

The number is greater than or equal to | `=COUNTIF(F9:F19,">=100")` |
Count cells where values are greater than or equal to 100. |

The number is less than or equal to | `=COUNTIF(F9:F19,"<=100")` |
Count cells where values are less than or equal to 100. |

**Note.**It's very important to

**enclose**the mathematical operator along with a number

**in the double quotes**.

If you want to change the criteria without altering the formula, you can reference the cells as well.

Let us reference A3 and put the formula in B3, just as we did before:

`=COUNTIF(F9:F19,A3)`

To create more sophisticated criteria, use an **ampersand** (&).

For example, B4 contains a formula which counts the number of values greater than or equal to 100 in the E9:E19 range:

`=COUNTIF(E9:E19,">="&A4)`

B5 has the very same criteria, but we reference not only the number in that cell, but also a mathematical operator. This makes it even easier to adapt COUNTIF formula if necessary:

`=COUNTIF(E9:E19,A6&A5)`

### Google Spreadsheet COUNTIF with multiple criteria

Sometimes it's necessary to count the number of values that answer **multiple criteria at once**. For that purpose, we should use a few COUNTIF functions in a single cell at a time.

Let's count the number of sales of black and white chocolate. To do that, enter the following formula in B4:

`=COUNTIF(D7:D17,"*Milk*") + COUNTIF(D7:D17,"*Dark*")`

Please note that we use asterisk (*) to ensure that the words "dark" and "milk" will be counted no matter where these words are in the cell - at the beginning, in the middle, or at the end.

Again, we can write the formula using the cell references. You can see how it looks like on the screenshot below in B3. The result remains the same:

Remember, using multiple criteria, we can count how many times a certain number appears within a certain range.

We are going to count the number of total sales between 200 and 400:

We take the number of totals under 400 and subtract the number of total sales under 200 using the next formula:

`=C0UNTIF(F7:F17,"<=400") - COUNTIF(F7:F17,"<=200")`

The formula returns the number of sales more than 200 but less than 400.

If we want to reference A3 and A4 that contain the criteria, the formula will be a bit simpler:

`=COUNTIF(F7:F17, A4) - COUNTIF(F7:F17, A3)`

A3 cell will have "<=200" criteria, while A4 - "<=400".

Put both formulas into B3 and B4 and make sure that the result doesn't change - 3 sales over the needed range.

### COUNTIF Google Sheets for blank and non-blank cells

With the help of COUNTIF we can also count the number of blank or non-blank cells within some range.

Let's suppose that we successfully sold the product and marked it as "Paid". If the customer declined the goods, we write zero (0) in the cell. If the deal wasn't closed, the cell remains empty.

To count **non-blank cells** with any value, use the following:

`=COUNTIF(F7:F15,"<>")`

or

`=COUNTIF(F7:F15,A3)`

To count the number of **empty cells**, make sure to put the COUNTIF formula in the following way:

`=COUNTIF(F7:F15,"")`

or

`=COUNTIF(F7:F15,A4)`

The number of cells with a **textual value** is counted like this:

`=COUNTIF(F7:F15,"*")`

or

`=COUNTIF(F7:F15,A5)`

Screenshot below shows that A3, A4, and A5 cells include our criteria:

Thus, we can see 4 closed deals, 3 of which were paid for and 5 of which have no markings yet and, consequently, are not closed.

### COUNTIF and conditional formatting

There is one interesting opportunity that Google Sheets offer - to **change the cell's format** (like its colour) depending on some criteria. For example, we can highlight the values that appear more often in green.

COUNTIF function can play a small part here as well.

Select the range of the cells that you want to format in some special way. Click *Format* -> *Conditional formatting...*

In the *Format cells if...* drop-down list choose the last option *Custom formula is*, and enter the following formula into the appeared field:

`=COUNTIF($B$10:$B$39,B10)/COUNTIF($B$10:$B$39,"*")>0.4`

It means that the condition will be answered if the value from B10 appears within B10:B39 in more than 40% of cases:

In a similar way, we add two more formatting rule criteria - if the cell value appears more often than in 25% of cases and more often than in 15%:

`=COUNTIF($B$10:$B$39,B10)/COUNTIF($B$10:$B$39,"*")>0.25`

`=COUNTIF($B$10:$B$39,B10)/COUNTIF($B$10:$B$39,"*")>0.15`

Keep in mind that the first criterion will be checked beforehand, and if it's met, the rest won't apply. That is why you'd better start with the most unique values moving to the most common ones. If the cell value doesn't meet any criteria, its format will remain intact.

You can see that the colour of the cells has changed according to our criteria.

To make sure, we also counted the frequency of some values in C3:C6 using COUNTIF function. The results confirm that COUNTIF in formatting rule was applied correctly.

All these function examples give us a clear understanding of how Google Spreadsheet COUNTIF offers multiple opportunities to work with the data in a most efficient way.

what is the formula for.

if a1 is less than b1, put good

if a1 is greater than or equal to b1, put bad

if a1 is less than b1 but greater than c1, put critical

put this in one formula?

Hi, Loise,

try this formula:

=IF(and(A1<B1,A1<=C1),"good",IF(AND(A1>B1,A1=B1),"bad",IF(AND(A1<B1,A1>C1),"critical","")))

You can read more about IF function in Google Sheets in this article.

Hope this helps!

I'm trying to search for the number of occurrences on a particular date. The info in the cell is the data and time stamp. How would I set up the formula so it is only pulling the date?

Hello, Lisa,

supposing, that the date an time are in A1, use the following formula in the cell where you want to return the date, A2 for example:

=DATEVALUE(A1)

Then select A2, and in the menu choose Format > Number > Date. You will see only the date from A1 in this cell.

Hope this is what you need!

What is the countif formula in goggle sheets if the possible choices included are as follows: >, <, or =. I have used the following formula and keep getting an answer of 0 students with the correct answer. However hundreds of students have the correct answer.

=countif(BL3,"<")

Hello, Mary,

If I understand your task correctly, there's something missing from your formula. You need to count if one value is greater/less than or equals to some other value. Also, please make sure to indicate the range of cells correctly in the first argument.

So, if your data is spread across B1:L3 and you need to count all the values that are less than 3, your formula should look like this:

=COUNTIF(B1:L3,"<3")

Please adjust your formula according to your data, and it should work :)

Is it possible to use, as a criterion, the background color of a cell in the countif function? For example, in column A (say from A5 to A10), there are two types of cells: those that have a green background color and those that are white. The range of cells to be added is in column B (say B5 to B10). I would like, in cell B11, to sum cells B5 to B10 if they are next to green cells. In cell B12, I would like to do the same for the cells next to the white cells.

I thought using Apps script, but I would prefer to use simple formulas.

Thank you.

[resolved]Finally, I decided not to use the background color as a criterion for selecting the cells to be added. I found a simpler solution, based on the content of the cells using the sumif function. Specifically, I used the following formula in cell C268:

SUMIF ($A5: $A267; "* (AFR)"; C5: C267)

In other words, instead of using the color, I select the cells whose content ends with the 5 characters: (AFR)

Merci

in google sheets, i'm trying to count the number of occurrences where column W=YES, IF column P=5. How can I write this formula?

Hello, Jess,

you can try the following formula:

=COUNTIFS(W:W,"YES",P:P,5)

Hello!

Is it possible to use COUNTIF to determine how many cells do not contain a particular letter? I understand how to use the formula when dealing with numbers, but mathematical symbols don't seem to work the same way with letters.

So, for example, if I want to know how many cells in A1:A25 do NOT contain G, how would I write that?

Thank you!