Ninja Excel BlogExcel formulas and functionsExcel COUNT IF: Simplifying our data counting

Excel COUNT IF: Simplifying our data counting

The COUNTSI function is one of the most used in Excel, discover here why and how

Key information:

The function COUNT YES allows us count elements of a selection of data (“range”) based on a condition (“criterion”) defined by us. Excel will evaluate the condition in each of the cells that we indicate and will see how many meet it. Then it will give us the total number of those that complied.

The basics:

  • Purpose: allows us to count cells in a range of data, according to a criterion defined by us. 
  • Characteristics: It is the union of two other Excel functions, COUNT and IF, in the same package. It can be used in any direction.
  • Syntax: =COUNTIF(range; criterion)
  • Arguments:
    • range = The selection of cells to be counted in
    • criterion = The condition according to which it will be counted

Step 1: Selecting a data range

When using the Excel COUNT IF function we have to select the data about which we want to count something. We call this “range” and it can be selected in any direction. In the following example we want to count the Xs inside the square:

Excel count.if count if range example

Since the table goes from B3 to E8, we select this array as our range:

Excel count.if count if example range result

Thus the range is defined as: 

  • range B3:E8

As we see in the example, the function correctly showed us that in our range there are 8 cells that contain the letter X:

Excel excel count.if count if example range x result

Make sure you select the cell range correctly to avoid errors.

Step 2: Defining a criterion

When applying the Excel COUNT YES function we must define a criterion, that is, the condition on which Excel will count our cells. This condition can take different forms depending on what we want to look for.

COUNT IF according to a numerical criterion:

We can use the function so that count the cells that contain the numerical criteria that we give you. Taking the example of the following image, We want to see how many people are 35 years old:

Excel count.if count if example exact number years

Since we are looking at the years, our range becomes the “Age” column, which goes from cell D4 to D8. In this case the condition is to be 35 years old, so the function includes a 35 as a criterion. So:

  • range = D4:D8 (Data column “Age”)
  • criterion = 35 (The person is 35 years old)

That is, our COUNTIF function corresponds to:

=COUNTIF (D4:D8,35)

This results in 2, that is, the number of cells that meet the condition:

Excel count.if count if example exact number years resultIn turn, the condition of the Excel function COUNT IF can be the value of another cell. In the image we see an example of how to enter this:

Excel count.if count if example exact number years another cellNow the condition is given by cell H4, which contains the number 35, so we will obtain the same result.

COUNT IF according to a criterion in words:

We can also use the Excel COUNT IF function to count according to a criterion in words. Now when writing the condition we must worry that the word is enclosed in quotes (“”), since with this we tell the COUNT IF function that it is a text. In the following example we want to count all the people named Juan:

Excel count.if count if example by name

We can see that now our range is the “Name” column. The result that COUNT IF will give us is 2.

As with numbers, it is possible to remove the condition from another cell, where it is not necessary to add quotes because the COUNTIF function will recognize that the original cell is text:

Excel count.if count if example by name another cell

The condition in this case comes from cell H3, which says Juan, so COUNT IF will count the number of times the name “Juan” is repeated in our range, and will give us a result of 2.

Logical operators

We can combine the Excel function COUNT IF with logical operators (>,<,<>,=) to make more complex numerical conditions. These operators are:

  • > Greater than
  • < Less than  
  • <> Different from
  • = Same
  • >= Greater than or equal to
  • <= Less than or equal to

Now we want the COUNT IF function to show us all those people who are over 30 years old. For this we use > (greater than) and 30 as parts of our condition. But since > corresponds to text, our entire condition must be enclosed in quotes:

Excel count.if count if example greater than

This function will give us a 4, since everyone except Juan Bilbao is over 30.

Suppose that now we want to count all those people who do not have the position of analyst. We use the COUNT IF function including the operator <> (not equal to) and the word analyst.

Excel count.if count if example different than

Our rank now is the charge column. This gives us the following result:

Excel count.if count if example different from result

Ninja Tip: The COUNT IF function does not recognize capital letters, so using “Analyst”, “analyst” or “AnAlIStA” as a condition gives the same result.

We can also use logical operators and conditions that come from a cell, but using the “&” character. In this case, it is the logical operator that is enclosed in quotes, but not &. The following image shows the example we used previously about people over 30 years old:

Excel count.if count if example greater than another cell

Ninja Tip: You can use this function by including other functions as conditions to achieve better results. An example is to use the Excel function AVERAGE and “>” to count those people who are above the average age.

Ninja Tip: COUNTBLANK is a variation of COUNTIF that counts the number of blank cells in a range, which can be useful when working with a lot of data to know how many are missing information.

Wild cards

There are certain characters that can be used in the COUNT IF function, known as “wildcards,” that allow special actions to be performed on the conditions.

Asterisk:

Depending on where the asterisk is located in the condition (*), it can tell the Excel COUNT IF function different things:

  • If it comes before the condition (example: “*dro”) it indicates that it may come something before what is written. In the example, the COUNT IF function will recognize “Pedro” and “Alejandro” as cells that meet the condition.
  • If it comes after the condition it indicates that it can come somewhat after what is written. If we now write the condition as “Pe*”, COUNTIF will recognize “Pedro”, but not “Alejandro”.
  • It can also come before and after the condition, indicating that something can come before and after what is written. If we write the condition as “*dro*”, COUNTIF will recognize “Pedro Pablo” as a cell that meets the condition.

In the following example we want to know how many names start with the letter “M”, so we write “M*” as a condition, since this way we tell Excel that the condition is that it starts with M, but that anything can come later :

Excel count.if count if example asterisk wildcard wildcardThis will give us a result of 2:

Excel count.if count if example asterisk wildcard wildcard resultQuestion mark:

The question mark (?) tells the function that any other character can go in the place where we place the sign. In the following example we want to see how many people are named Juan or Joan, who only differ in the second character, which we replace with “?”, to tell Excel that any character is allowed in that place:

Excel count.if count if example question mark wildcard wildcard

This will give us a result of 2, since Excel recognizes the names Juan and Joan as meeting the condition:

Excel countif countif example question mark wildcard wildcard resultWe must remember that the “?” replaces only one character, so in the previous example COUNT IF does not include Julian. If we wanted to count how many Juliáns there are, the condition would be “J???án”.

COUNT IF SET: Counting according to several criteria

  • Purpose: COUNT IF SET is similar to COUNT IF, but allows you to include different conditions to obtain a single result.
  • Characteristics: Only the first range and criteria are required, as you can have up to 126 extra range/criteria pairs. Extra ranks cannot exceed the size of the first rank.
  • Syntax: =COUNTIF.SET(criteria_range1; criterion1, [criteria_range2; criterion2]; …)
  • Arguments:
    • criteria_range1  = Range where criterion 1 is evaluated
    • criterion1 = Condition upon which it is counted in rank 1
    • criteria_range2, criterion2… = Extra pairs of ranges and criteria

The Excel function COUNT IF SET allows us to count data based on several criteria. In the following example we want to see how many people are over 30 years old and are analysts. For this, our first condition will be that the person is over 30 years old and their rank will be the “Age” column. Our second condition will be that the person is an analyst and their rank will be the “Position” column:

Excel excel count.if count if count.if.set count if set example greater than conditionThe elements that our COUNT IF SET function must contain are:

  • criteria_range1  = D4:D8 (Column “Age”)
  • criterion1 =  “>30” (Being over 30)
  • criteria_range2  = E4:E8 (Column “Position”)
  • criterion2  = Analyst (Be an analyst)

That is, our function corresponds to:

=COUNTIF SET(D4:D8,”>30”, E4:E8, “Analyst”)

The result we obtain is 1, since only María Tapia meets both conditions:

Excel excel count.if count if count.if.set count if set example greater than condition result

Nested If and And: Learning to combine both functions

Combining the Excel IF and AND functions allows us to check different conditions, so that we then obtain a predetermined result depending on whether these conditions are met or not. This is useful for analyzing different types of information, but summarizing the result in the same cell.

You can complement your learning with the following video:

The basics

To combine functions YEAH and AND, it is necessary to understand each of the two:

IF function:

Purpose: The IF function allows us to evaluate whether a condition is true or false. If true, it performs a given action, otherwise it performs another action. 

Characteristics: Allows you to evaluate with different symbols, for example, equal, less, greater than or equal, unequal, etc. Numeric or text values can also be evaluated in the logic test.

Syntax: =IF(logical_test; [value_if_true]; [value_if_false]

Arguments:

logic_test = Required. Value or expression that we seek to evaluate.

value_if_true = Optional. Value delivered when the evaluation is true. This value can be text, calculations, a reference to another cell, or other functions.

value_if_false = Optional. Value delivered when the evaluation is false. This argument is optional, if not set, Excel will respond “FALSE” automatically.

For more information and examples of how to use the IF function you can go to the following article.

AND function

Purpose: The function AND It allows us to know if all the conditions of a logical proof are true.

Characteristics: If all the arguments are true, it returns “TRUE” as a result (logical value). In any other case, it gives us “FALSE” as a result.

Syntax:

=Y(logical_value1;[logical_value2];…

Arguments:

logical_value1 = Required. First of the logical values to evaluate. It can be a condition, the important thing is that the result has to be a logical value (TRUE OR FALSE)

logical_value2; … = Optional. The rest of the logical values to evaluate. It can be a condition, the important thing is that the result has to be a logical value (TRUE or FALSE)

Understanding the IF function

The IF function allows us to evaluate conditions in a cell or selection of cells. These conditions can be with arguments that are in text or numeric format. The only thing to remember is that if we are dealing with an argument in text format we must write it between quotes (“”). Also very common are logical operators (>,<,=,etc).

In the following example we want to see if people have a salary greater than $100:

Excel IF function AND combine 2 conditions explanation

How we can see the arguments of the IF function are as follows:

logic_test = C3>$100

value_if_true = Yes

value_if_false = No

So the function will evaluate the argument found in the “Salary” column and see if it corresponds to a value greater than $100. If it is, the function will understand the logical test as “TRUE”, in which case it will return the word “Yes”. If it is not, it will understand it as a “FALSE” and will deliver the word “No”. In this way the results are the following:

Excel function IF AND combine 2 conditions explanation result greater than

Let's see what happens if we want to include text in the condition as well. Let's assume that now in the example we want to give a bonus to people with a salary less than or equal to $100:

Excel function IF AND combine 2 conditions explanation example bonus

Now the condition is that the column “Salary greater than $100? be equal to “No”. When it is met, the word “Bonus” appears in the “Complement” column, while when it is not met this cell remains blank:

Excel function IF AND combine 2 conditions explanation example bonus result

Understanding the Y function

Excel's AND function will help us know if different cells or conditions are all true (in logical value). To understand this, let's look at the following example, where we want to know if all the people are over 18 years old:

Excel function IF AND combine 2 conditions explanation example age

In this case, in the column “Are you over 18 years old? We only leave a logical test, which corresponds to seeing if the cell to its left corresponds to a number greater than 18. In this way, the result can only be “TRUE” or “FALSE” which correspond to logical values:

Excel function IF AND combine 2 conditions explanation example age logical values

Now we use Excel AND function to see if all logical values are true:

Excel function IF AND combine 2 conditions explanation example age logical values test

And since all the included cells are true, the result is also true:

Excel function IF AND combine 2 conditions explanation example age logical values answer

However, if we now make one of the ages not meet the condition, the general result becomes false:

Excel function IF AND combine 2 conditions explanation example age logical values false case

Ninja Tip: The AND function omits those cells whose result is not a logical value, so we must be careful not to lead to general conclusions that are wrong. For example, if instead of saying “FALSE” when the condition was not met you said “No”:

Excel function IF AND combine 2 conditions explanation example age logical values case tip ninja

Here “Dusan Radic” does not meet the condition, but the result is not a logical value, so the AND function does not recognize it and indicates that everyone is over 18 years old.

Alternatively, we can do the different logical tests directly in the Y function, which will obtain the same result:

Excel function IF AND combine 2 conditions explanation example age logical values summarized
Excel function IF AND combine 2 conditions explanation example age logical values summarized result

Combining Excel IF and AND functions

Having understood each of the Excel IF and AND functions, combining them is very simple. What we will do is use the AND function to evaluate different conditions, so that later with that result the SI function determines what we want it to deliver to us in the cell itself.

In the following example we want to give a bonus to those people who are over 30 years old and earn less than $100:

Excel function IF AND combine 2 conditions bonus example

In this case the arguments of the IF function are:

logic_test = Y(C3>30;D3<10)

value_if_true = Yes

value_if_false = No

As we can see, the logical test is to meet both conditions (using the AND function), that the cell in the “Age” column is greater than 30 and that the “Salary” column is less than 100. Only in that case the IF function tells us will deliver the text “Yes”:

Excel function IF AND combine 2 conditions example bonus result

In the example, only Clemente Baraona meets both conditions, making him the only person who has a bonus.

This method of combining functions also works if the conditions refer to the same cell. For example, now we only want there to be a bonus if the salary is less than $150, but greater than $60:

Excel function IF AND combine 2 conditions example same cell

With which we obtain the following result:

Excel function IF AND combine 2 conditions example same cell result

Ninja Tip: The rest of the arguments of the IF function can also be function operations. For example, we may want the SI function to give us the 10% of the salary when there is a bonus, so we only multiply the cell in the “Salary” column by the 10%:

Excel IF function and combine 2 conditions example tip ninja
Excel function IF AND combine 2 conditions example tip ninja result

Ninja Tip: Everything previously learned can also be used by replacing the AND function with the function EITHER to check if any of all the conditions that we give to the IF function are true.​

Frequent questions

How to count cells with text in Excel?

To count cells with text in Excel we can use the function =COUNTIF

How to count cells in Excel with multiple criteria?

To count cells in Excel with several criteria use =COUNTIF.SET you can use it as follows: =COUNTIF.SET(A1:A10,”criterion 1″,A1:A10,”criterion2″)

How to count non-zero values in Excel?

To count the number of values different from 0 we can use the following formula =COUNTIF(A1:A10;”0″)

How do you use the count if set?

The COUNTIF SET function applies criteria to cells in multiple ranges and counts the number of times all criteria are met.

How do you use the count if function in Excel?

The COUNTIF function counts the number of cells in a range that meet the criteria we previously established

How do you use the count if function?

COUNT IF helps us count the number of times a criterion is met within a range of cells, for example to count the number of times a word appears within a list.

How do you use the count function in Excel?

CONTARA helps us count all the cells that have some type of information, it will only not count the empty cells.

How to use the count if function?

COUNT IF helps us count the number of times a criterion is met within a range of cells, for example to count the number of times a word appears within a list.

What is the difference between count if and count if set?

The BIG difference is that COUNTIF SET allows counting based on several conditions, and COUNTIF does not.

What are the arguments to the count if function?

The necessary arguments of the COUNTIF function are: RANGE (The range where the values are found) and CRITERIA (The condition that we will determine to count)

Ninja Excel Newsletter &#55357;&#56560;  

Commercial engineer and Master in Finance from the Pontifical Catholic University. Special interest in topics related to corporate finance, private equity and real estate investment.

white ninja excel logo

The leading Excel training platform for companies.

Company

Copyright © 2024 Ninja Excel.

English