Countif excel and criteria

COUNTIF function

Use COUNTIF, one of the statistical functions, to count the number of cells that meet a criterion; for example, to count the number of times a particular city appears in a customer list.

In its simplest form, COUNTIF says:

  • =COUNTIF(Where do you want to look?, What do you want to look for?)

For example:

  • =COUNTIF(A2:A5,»London»)

  • =COUNTIF(A2:A5,A4)

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

COUNTIF(range, criteria)

Argument name

Description

range    (required)

The group of cells you want to count. Range can contain numbers, arrays, a named range, or references that contain numbers. Blank and text values are ignored.

Learn how to select ranges in a worksheet.

criteria    (required)

A number, expression, cell reference, or text string that determines which cells will be counted.

For example, you can use a number like 32, a comparison like «>32», a cell like B4, or a word like «apples».

COUNTIF uses only a single criteria. Use COUNTIFS if you want to use multiple criteria.

Examples

To use these examples in Excel, copy the data in the table below, and paste it in cell A1 of a new worksheet.

Data

Data

apples

32

oranges

54

peaches

75

apples

86

Formula

Description

=COUNTIF(A2:A5,»apples»)

Counts the number of cells with apples in cells A2 through A5. The result is 2.

=COUNTIF(A2:A5,A4)

Counts the number of cells with peaches (the value in A4) in cells A2 through A5. The result is 1.

=COUNTIF(A2:A5,A2)+COUNTIF(A2:A5,A3)

Counts the number of apples (the value in A2), and oranges (the value in A3) in cells A2 through A5. The result is 3. This formula uses COUNTIF twice to specify multiple criteria, one criteria per expression. You could also use the COUNTIFS function.

=COUNTIF(B2:B5,»>55″)

Counts the number of cells with a value greater than 55 in cells B2 through B5. The result is 2.

=COUNTIF(B2:B5,»<>»&B4)

Counts the number of cells with a value not equal to 75 in cells B2 through B5. The ampersand (&) merges the comparison operator for not equal to (<>) and the value in B4 to read =COUNTIF(B2:B5,»<>75″). The result is 3.

=COUNTIF(B2:B5,»>=32″)-COUNTIF(B2:B5,»<=85″)

Counts the number of cells with a value greater than (>) or equal to (=) 32 and less than (<) or equal to (=) 85 in cells B2 through B5. The result is 1.

=COUNTIF(A2:A5,»*»)

Counts the number of cells containing any text in cells A2 through A5. The asterisk (*) is used as the wildcard character to match any character. The result is 4.

=COUNTIF(A2:A5,»?????es»)

Counts the number of cells that have exactly 7 characters, and end with the letters «es» in cells A2 through A5. The question mark (?) is used as the wildcard character to match individual characters. The result is 2.

Common Problems

Problem

What went wrong

Wrong value returned for long strings.

The COUNTIF function returns incorrect results when you use it to match strings longer than 255 characters.

To match strings longer than 255 characters, use the CONCATENATE function or the concatenate operator &. For example, =COUNTIF(A2:A5,»long string»&»another long string»).

No value returned when you expect a value.

Be sure to enclose the criteria argument in quotes.

A COUNTIF formula receives a #VALUE! error when referring to another worksheet.

This error occurs when the formula that contains the function refers to cells or a range in a closed workbook and the cells are calculated. For this feature to work, the other workbook must be open.

Best practices

Do this

Why

Be aware that COUNTIF ignores upper and lower case in text strings.


Criteria
aren’t case sensitive. In other words, the string «apples» and the string «APPLES» will match the same cells.

Use wildcard characters.

Wildcard characters —the question mark (?) and asterisk (*)—can be used in criteria. A question mark matches any single character. An asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) in front of the character.

For example, =COUNTIF(A2:A5,»apple?») will count all instances of «apple» with a last letter that could vary.

Make sure your data doesn’t contain erroneous characters.

When counting text values, make sure the data doesn’t contain leading spaces, trailing spaces, inconsistent use of straight and curly quotation marks, or nonprinting characters. In these cases, COUNTIF might return an unexpected value.

Try using the CLEAN function or the TRIM function.

For convenience, use named ranges

COUNTIF supports named ranges in a formula (such as =COUNTIF(fruit,»>=32″)-COUNTIF(fruit,»>85″). The named range can be in the current worksheet, another worksheet in the same workbook, or from a different workbook. To reference from another workbook, that second workbook also must be open.

Note: The COUNTIF function will not count cells based on cell background or font color. However, Excel supports User-Defined Functions (UDFs) using the Microsoft Visual Basic for Applications (VBA) operations on cells based on background or font color. Here is an example of how you can Count the number of cells with specific cell color by using VBA.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Get live and free answers on Excel

See also

COUNTIFS function

IF function

COUNTA function

Overview of formulas in Excel

IFS function

SUMIF function

Need more help?

The COUNTIFS function counts cells in a range that meet one or more conditions, referred to as criteria. To apply conditions, the COUNTIFS function supports logical operators (>,<,<>,=) and wildcards (*,?) for partial matching. The COUNTIFS function is a common, widely used function in Excel, and can be used to count cells that contain dates, numbers, and text.

Syntax

The syntax for the COUNTIFS function depends on the criteria being evaluated. Each separate condition will require a range and a criteria. The generic syntax looks like this:

=COUNTIFS(range1,criteria1) // 1 condition
=COUNTIFS(range1,criteria1,range2,criteria2) // 2 conditions

The first two arguments, range1 and criteria1 are required. Range1 is the range to which criteria1 should be applied. Range2 is the range to which criteria2 should be applied. Additional conditions are applied by providing more range and criteria arguments: the third condition is defined by range3 and criteria3, the fourth condition is defined by range4 and criteria4, and so on. When using COUNTIFS, keep the following in mind:

  • To be included in the final result, all conditions must be TRUE.
  • All ranges must be the same size or COUNTIFS will return a #VALUE! error.
  • Criteria should include logical operators (>,<,<>,<=,>=) as needed.
  • Each new condition requires a separate range and criteria.

Criteria

The COUNTIFS function supports logical operators (>,<,<>,=) and wildcards (*,?) for partial matching. Because COUNTIFS is in a group of eight functions that split logical criteria into two parts, the syntax is a bit tricky. Each condition requires a separate range and criteria, and operators need to be enclosed in double quotes («»). The table below shows some common examples:

Target Criteria
Cells greater than 75 «>75»
Cells equal to 100 100 or «100»
Cells less than or equal to 100 «<=100»
Cells equal to «Red» «red»
Cells not equal to «Red» «<>red»
Cells that are blank «» «»
Cells that are not blank «<>»
Cells that begin with «X» «x*»
Cells less than A1 «<«&A1
Cells less than today «<«&TODAY()

Notice the last two examples use concatenation with the ampersand (&) character. When a criteria argument includes a value from another cell, or the result of a formula, logical operators like «<» must be joined with concatenation. This is because Excel needs to evaluate cell references and formulas first to get a value before that value can be joined to an operator.

Basic example

With the example shown, COUNTIFS can be used to count records using 2 criteria as follows:

=COUNTIFS(C5:C14,"red",D5:D14,"tx") // red and TX
=COUNTIFS(C5:C14,"red",F5:F14,">20") // red and >20

Notice the COUNTIFS function is not case-sensitive.

Double quotes («») in criteria

In general, text values need to be enclosed in double quotes, and numbers do not. However, when a logical operator is included with a number, the number and operator must be enclosed in quotes as shown below:

=COUNTIFS(A1:A10,100) // count equal to 100
=COUNTIFS(A1:A10,">50") // count greater than 50
=COUNTIFS(A1:A10,"jim") // count equal to "jim"

Note: showing one condition only for simplicity. Additional conditions must follow the same rules.

Value from another cell

When using a value from another cell in a condition, the cell reference must be concatenated to an operator when used. In the example below, COUNTIFS will count the values in A1:A10 that are less than the value in cell B1. Notice the less than operator (which is text) is enclosed in quotes, but the cell reference is not:

=COUNTIFS(A1:A10,"<"&B1) // count cells less than  B1

Note: COUNTIFS is one of several functions that split conditions into two parts: range + criteria. This causes some inconsistencies with respect to other formulas and functions.

Not equal to

To construct «not equal to» criteria, use the «<>» operator surrounded by double quotes («»). For example, the formula below will count cells not equal to «red» in the range A1:A10:

=COUNTIFS(A1:A10,"<>red") // not "red"

Blank cells

COUNTIFS can count cells that are blank or not blank. The formulas below count blank and not blank cells in the range A1:A10:

=COUNTIFS(A1:A10,"<>") // not blank
=COUNTIFS(A1:A10,"") // blank

Dates

The easiest way to use COUNTIFS with dates is to refer to a valid date in another cell with a cell reference. For example, to count cells in A1:A10 that contain a date greater than a date in B1, you can use a formula like this:

=COUNTIFS(A1:A10, ">"&B1) // count dates greater than A1

Notice we concatenate the «>» operator to the date in B1, but and are no quotes around the cell reference.

The safest way to hardcode a date into COUNTIFS is with the DATE function. This guarantees Excel will understand the date. To count cells in A1:A10 that contain a date less than September 1, 2020, you can use:

=COUNTIFS(A1:A10,"<"&DATE(2020,9,1)) // dates less than 1-Sep-2020

Wildcards

The wildcard characters question mark (?), asterisk(*), or tilde (~) can be used in criteria. A question mark (?) matches any one character, and an asterisk (*) matches zero or more characters of any kind. For example, to count cells in A1:A5 that contain the text «apple» anywhere, you can use a formula like this:

=COUNTIFS(A1:A5,"*apple*") // count cells that contain "apple"

The tilde (~) is an escape character to allow you to find literal wildcards. For example, to count a literal question mark (?), asterisk(*), or tilde (~), add a tilde in front of the wildcard (i.e. ~?, ~*, ~~).

OR logic

The COUNTIFS function is designed to apply multiple criteria, but conditions are applied with AND logic. This means if you try to count cells that contain «red» or «blue» in the same range, the result will be zero (0). However, to count cells with OR logic, you can use an array constant and the SUM function like this:

=SUM(COUNTIFS(range,{"red","blue"})) // red or blue

The formula above will count cells in range that contain «red» or «blue». Briefly, COUNTIFS returns two counts in an array (one for «red» and one for «blue») and the SUM function returns the sum as a final result. For more information, see this example.

Limitations

The COUNTIFS function has some limitations you should be aware of:

  • Conditions in COUNTIFS are joined by AND logic. In other words, all conditions must be TRUE in order for a cell to be included in a count. The workaround above can be used in simple situations.
  • The COUNTIFS function requires actual ranges for all range arguments; you can’t use an array. This means you can’t alter values that appear in a range argument before applying criteria.
  • COUNTIFS is not case-sensitive. To count values based on a case-sensitive condition, you can use a formula based on the SUMPRODUCT function with the EXACT function.
  • COUNTIFS has some other quirks, which are detailed in this article.

The most common way to work around the limitations above is to use the SUMPRODUCT function. In the current version of Excel, another option is to use the newer BYROW and BYCOL functions.

Notes

  • Multiple conditions are applied with AND logic, i.e. condition 1 AND condition 2, etc.
  • All ranges must be the same size. If you supply ranges that don’t match, you’ll get a #VALUE error.
  • Non-numeric criteria must be enclosed in double quotes (i.e. «<100»,  «>32», «TX»).
  • The wildcard characters ? and * can be used in criteria. A question mark matches any one character and an asterisk matches any sequence of characters.
  • To match a literal question mark(?) or asterisk (*), use a tilde (~) like (~?, ~*).

The COUNTIF function is included in the group of statistical functions. It allows you to find the number of cells by a certain criterion. The COUNTIF function works with numeric and text values, as well as with dates.



Syntax and features of the function

First, let’s consider the arguments:

COUNTIF.

  • Range – the group of values for analysis and counting (required).
  • Criteria – the condition by which cells are to be counted (required).

The range of cells can include textual and numerical values, dates, arrays, and references to numbers. The function ignores empty cells.

A criterion can be a reference, a number, a text string, or an expression. The COUNTIF function only works with one criterion (by default). However, you can “force” it to analyze two criteria simultaneously.

Recommendations for the correct operation of the function:

  1. If the COUNTIF function refers to a range in another workbook, this workbook must be opened.
  2. The «Criteria» argument must be enclosed in quotation marks (except for references).
  3. The function does not take into account the letter case.
  4. When formulating a counting condition, you can use wildcard characters. The question mark «?» is any character. The asterisk «*» is any sequence of characters. For the formula to search for these signs directly, put a tilde (~) before them.
  5. For normal operation of the formula, cells with text values should not contain spaces or non-printable characters.



Countif function in Excel: examples

Let’s count the numerical values in one range. The counting condition is one criterion.

We have the following table:

following table.

Count the number of cells with numbers greater than 100. Formula: =COUNTIF(B1:B11,»>100″). The range is В1:В11. The counting criterion is «>100». The result:

umbers greater.

If the counting condition is entered in a separate cell, you can use the reference as a criterion:

reference as a criterion.

Count the text values in one range. The search condition is one criterion. Formula: =COUNTIF(A1:A11,A3).

Formula.

Or used reference inside the table:

inside table.

In the second case, the cell reference was used as a criterion, result is the same – 2.

Formula with the wildcard character application: =COUNTIF(A1:A11,»Tab*»). To calculate the number of values ending in «и» and containing any number of characters: =COUNTIF(A1:A11,»*s»). We obtain:

result.

All names that end with a letter «s».

We use the search condition «not equal» in the COUNTIF.

Formula: =COUNTIF(A1:A11,»<>»&»Stools»). The operator «<>» means «not equal». The ampersand sign (&) is used to merge this operator and the “Stools” value.

Stools.

When you apply a reference, the formula will look like this:

apply a reference.

Often you need to perform the COUNTIF function in Excel by two criteria. In this way, you can significantly expand its capabilities. Let’s consider special cases of using the COUNTIF function in Excel and examples with two criteria.

  1. Let’s count how many cells are contained in the » Tables » and » Chairs » text. Formula:

    To specify several criteria, several COUNTIF phrases are used. They are united by the «+» operator.

  2. .

  3. Criteria – cell references. Formula:

    The function searches for » Tables » text in cell A1 and » Chairs » text – in cell A2 based on the criterion.

  4. based on the criterion.

  5. Count the number of cells in B1:B11 range with a value greater than or equal to 100 and less than or equal to 200. Formula:
  6. value greater.

  7. Apply several ranges in the COUNTIF function. This is possible if the ranges are contiguous. It searches for values by two criteria in two columns simultaneously. If the ranges are not adjacent, then the COUNTIFS function is used.
  8. simultaneously.

  9. When the criterion is a reference to a range of cells with conditions, the function returns the array. To enter a formula, you need to highlight as many cells as the range with criteria contains. After entering the arguments, simultaneously press Shift + Ctrl + Enter control key combination. Excel recognizes the formula of the array.

array.

COUNTIF with two criteria in Excel is very often used for automated and efficient data handling. Therefore, an advanced user is highly recommended to carefully study all of the examples above.

Subtotal command and the countif function

Count the number of goods sold in groups.

  1. First, sort the table so that the same values are close.
  2. Sort.

  3. The first argument of the formula “SUBTOTAL” – “Function number”. These are numbers from 1 to 11, indicating a statistical function for calculating the intermediate result. Counting the number of cells is carried out under number «2» (“COUNT”).

SUBTOTAL.

Download example COUNTIF in Excel

The formula has found the number of values for the «Chairs» group. For a large number of rows (more than a thousand), this combination of functions can be useful.

Excel tables with their functions come in handy to count cells with data, horizontally and vertically. COUNTIF is the common function for counting cells with one and several conditions. So let’s look into this further to understand all the details and distinctions.

Meaning of COUNTIF Excel

COUNTIF in Excel is a statistical function that counts cells with those data that users indicate. It takes into account one condition. 

  • You can find items recorded even for months under a specific name. 
  • You may count the number of cells that hold a common letter or sign. 
  • You can use the Excel COUNTIF not blank to learn the empty cells quantity.
  • You specify numerosity more or less than a mentioned value.

The COUNTIF formula in Excel consists of range (which goes first) and criteria (indicates the corresponding position). 

=COUNTIF (range, criterion) 
  • range is the mandatory argument, which includes cells needed to find. 
  • criterion includes expression, word, figures, letter, or other conditions that you need to discover.

How to use COUNTIF in Excel?

The function works with only one condition. Nevertheless, a person may single out many different data in turn. The computation is carried out with numbers, letters, words, phrases and dates. You can only write a cell reference or an entire condition. Sometimes, wildcards and symbols assist to determine more accurate values.

How COUNTIF works in Excel?

The function calculates the number of cells with indicated context, i.e., with the data that the user needs to count. For instance, you have a chart with diversified furniture bought over time. You may count what furniture (sofa, bed, wardrobe, chair, table, etc.) people buy. The COUNTIF will compute the cells in which the mentioned furniture is located. You write down the formula according to the condition you ought to detect. For example, let’s count the number of cells containing the word ‘chair‘:

=COUNTIF(A1:A21,"Chair")

1 countif function example

Does COUNTIF function in Excel work for several criteria?

The COUNTIF doesn’t support frequentative conditions. Thus, you won’t find the number of chairs or nightstands purchased only in January or only on February 3. You have to use COUNTIFS for such cases.

However, you may write COUNTIF + COUNTIF. Such a COUNTIF Excel multiple criteria function makes the outcome more complete. Let’s determine the number of purchased chairs and sofas. Write the following:

=COUNTIF(A2:A21,"Chair")+COUNTIF(A2:A21,"Sofa").

2 countif function several criteria example

Samples of advanced COUNTIFS function in Excel 

COUNTIF and COUNTIFS are various functions. They differ in the computation of cells with one criterion or more criteria. The first identifies cells under one condition, and the second takes into account several specific criteria. Let’s count the number of chairs bought by Jeremy. We need to use COUNTIFS for such appointments. Write it as follows: 

=COUNTIFS(A2:A13,"Chair",B2:B13,"Jeremy")

3 advanced countifs function example

Using COUNTIF in Excel when data is on other sources

People usually store data on certain apps, such as Harvest, Google Drive, Jira, Pipedrive, etc. When you need to calculate this data in Excel, you can import it from the app. The Coupler.io tool is designed exactly for this. It will help transfer all the necessary information to BigQuery, Google Sheets, or Excel from other sources. In addition, you can automate updates to make your work easier in the future. 

1 excel integrations coupler

Sign up to Coupler.io and complete two steps to set up your Excel integration: source and destination. If you want to schedule automatic data refresh, you’ll need to configure one more step – schedule. Here is what the integration may look like:

excel integration

Practical skills based on a COUNTIF Excel example

Examine a few samples of use in more detail. Take, for instance, the furniture in the store. Imagine the owner created an Excel table regarding sales. They write down the furniture in one column there. The other column contains the dates when the goods were sold. Finally, the third column contains the quantity of each product sold. So, let’s define some samples with several formulas, including dates, words and figures.

4 practical skills countif example

Excel COUNTIF: Cells are equal or not equal

Imagine that people have bought every subject several times. Let’s take, for example, 7 times. In our formula, we specify the range where to look and the figure 7. 

=COUNTIF(B1:B20,7)

5 equal countif formula example

Let’s still find the purchased furniture that isn’t equal to 5.

=COUNTIF(B1:B20,"<>5")

6 not equal countif formula example

Excel COUNTIF: cells contain words

Let’s try to work with words using the same formula. Imagine that we need to know how many tables people bought. Let’s write the following formula. 

=COUNTIF(A2:A21,"Table")

7 countif formula with words example

As a result, people bought 2 tables. You can replace the word with a cell reference

=COUNTIF(A2:A21,E2)

8 countif formula cell reference example

COUNTIF use in Excel – meaning of wildcards

We can use COUNTIF not only with words but also with special wildcards (* and ?) to generalize the condition. 

  • ? = One character.
  • * = Sequence. 

Also, you can write ~ to find symbols * or ?.

Let’s look at a simple formula 

=COUNTIF(A1:A7,"Table")

9 countif with words example

The question mark symbol ? adds one additional character. In our dataset, there are the words ‘Table‘ and ‘Tables‘ with the last letter ‘s‘. So, Table? in the formula will look for the latter option:

=COUNTIF(A1:A7,"Table?")

10 countif question mark symbol example

The asterisk symbol * adds a sequence of characters or even spaces. For instance, the following formula counts all words that start with Tab including ‘Table’ and ‘Tables’:

=COUNTIF(A1:A7,"Tab*")

11 countif asterisk symbol example

Excel COUNTIF: сells are more than or less than

Let’s find out some values using operators: >, <, <>, =. We write it next to the criterion in quotation marks. Thanks to them, we can find cells with numbers that are more or less, equal, or not equal to some value. For example, let’s count the amount of furniture that people bought more than 3 times:

=COUNTIF(B1:B20,">3")

12 countif using operator more than

Change the logical operator to count the amount of furniture that people bought less than 3 times:

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

13 countif using operator less than

Excel COUNTIF: count cells including date

Another feature is working with dates. So, let’s imagine that the biggest purchases fall on the date of January 1. We need to know the cells’ numerosity with this data.

=COUNTIF(B2:B21,"01/01/2021")

14 countif formula with dates

What common problems should you avoid? 

Often, people face issues using the function. We seem to be doing everything right, but the Excel function COUNTIF shows the error. Look at a few situations why it occurs. For instance, you wrote the formula 

=COUNTIF(A2:A13,Chair)

15 countif problems zero results

The function has shown zero results although this is not correct. So taking a closer look, the word ‘Chair‘ should be in quotation marks. 

=COUNTIF(A2:A13,"Chair")

In another example of incorrect syntax, the formula returned #NAME?. In this case, there is a space between the range (A1:A7) and the criterion, which also has not quotation marks (Table).

16 countif problems missing characters

The correct formula should look like this

=COUNTIF(A1:A7,"Table")

Best practices in using the COUNTIF function

It is easy to make mistakes both out of ignorance and inattention. However, by applying the following tips you can avoid the common mistakes.

  • Write the wildcards (? and *) to generalize the condition.
  • The condition can only have less than 255 characters. You will see an error exceeding this limit. To exceed the limit, you can use CONCATENATE or ampersand (&).
  • The function returns the same value if the words are written in uppercase or lowercase letters. It doesn’t take into account case strings. You should rename the word if it has a different meaning.
  • Pay attention to the spelling of words and letters. The function does not differentiate case strings and doesn’t work with misspellings.

Adherence to all principles and rules and writing correct syntax will facilitate calculations without problems. The main point is to write the formula and condition correctly.

  • Piotr Malek

    Technical Content Writer on Coupler.io who loves working with data, writing about it, and even producing videos about it. I’ve worked at startups and product companies, writing content for technical audiences of all sorts. You’ll often see me cycling🚴🏼‍♂️, backpacking around the world🌎, and playing heavy board games.

Back to Blog

Focus on your business

goals while we take care of your data!

Try Coupler.io

Понравилась статья? Поделить с друзьями:
  • Countif and countifs functions in excel
  • Countif and countifs function in excel
  • Countbycolor excel на русском
  • Countblank excel на русском
  • Countable uncountable word wall