
The COUNTIFS function is a statistical function that counts the rows that meet specific conditions.
This is an extremely useful function for creating reports and summarizing complex situations, and it is equivalent to counting the elements that match one or more filters.
To learn how to use the COUNTIFS function, keep in mind that it consists of several parts:
- criteria_range1 [ the field that will be filtered based on the first condition ]
- criteria1 [ the first condition ]
- criteria_range2 [ the field that will be filtered based on the second condition ]
- criteria2 [ the second condition ]
=COUNTIFS(criteria_range1,criteria1,[criteria_range2,criteria2],…)
The first two elements of the function must be included, while the others are optional. In fact, the function requires that at least one “criteria_range”/“criterion” pair be defined for filtering. Additional conditions can be added to this, up to a total of 127.
You may have encountered the COUNTIF function in the past, the problem with this function is that it allows only a single starting condition, so it’s advisable to update all files using the COUNTIFS function. Even if you use only one condition, using COUNTIFS will ensure consistency across your files and allow you to expand the formulas if necessary.
To illustrate how to use the COUNTIFS function, we’ve included data from a company that operates gyms in various cities across Italy. This is a fictional dataset created solely to test the function.
To simplify the explanation, the dataset has been formatted as a Table to make the formulas easier to read, you’ll therefore see that all formulas include “TBL” to indicate the source table.

How to Use the COUNTIFS Function with a Text Condition

Generally, COUNTIFS is used to count based on text conditions across different columns in Excel. Specifically, the simplest use involves setting a single condition, represented in this case by the LOCATIONS field in the source table (in red) and criterion1 (LOCATION) in the summary table (in blue).
Assuming we want to count the number of times H3 appears in our source table:
=COUNTIFS(TBL[LOCATIONS],H3)
The function applies the PESCARA filter to the table, finding four matching rows. The advantage of linking this formula to a cell is its scalability, since we can then enter any value we choose in cell H3 and receive the result for other cities as well, such as Bologna.
How to Use the COUNTIFS Function with Multiple Text Conditions

Of course, the COUNTIFS function can also be used when we want to count a range with multiple conditions. What would we need to change if we wanted to know how many annual passes were sold in a certain city?
In this case, we’d simply need to add a second condition based on the subscription type, for example, if we want to count only annual subscriptions:
=COUNTIFS(TBL[LOCATIONS],K3,TBL[Subscription],L3)
In this case, we’re adding the new column TBL[Subscription] and its corresponding condition, but the preceding part remains exactly the same. You can therefore create even more complex operations by including 3 or 4 criteria, but be careful not to create overly complicated formulas.
Note: criteria_range1 and criteria_range2 must always be the same size.
In our example, this is handled automatically by using the table format, which is highly recommended for this type of operation. If you set the ranges manually, always check that the column widths are the same; otherwise, an error will be returned.
How to use the COUNTIFS function with a word contained in a cell

You may need to use COUNTIFS even if a certain string is contained in an Excel cell. This is a typical scenario when you have numerous text values entered in a specific cell of a column, for example, “Audi A4 Car,” “Fiat 500X Car,” “Kawasaki Eliminator Motorcycle,” and “Volkswagen T-Roc Car”, and you want to count all the cars in the system. Unfortunately, you cannot select only “CAR” because that would result in an error, since Excel would search for all cells that are written exactly that way, only with “CAR” and without any additional specifications.
In this case, you need to use an expression containing a wildcard character. For example, to count all instances of “ROOM,” since the larger database might also include “ROOM PILATES,” “ROOM CROSSFIT,” and “ROOM CLIMBING”:
=COUNTIFS(TBL[COURSE],"*"&O3&"*")
This condition contains the wildcard character, which matches “any character.”
In this case, for example, cell O3 contains the word “ROOM”, so "*"&O3&"*" is equivalent to "*ROOM*".
In turn, this expression is equivalent to filtering on all cells containing the word “ROOM,” since there can be “any character” before or after it. The notation is a bit convoluted, but once you’ve gotten the hang of it, these calculations will be much simpler.
EXCEL TRAINING
Want to bring these skills to your team?
I design Excel training paths based on your goals, the participants' level and the cases you actually face at work.

Marco Filocamo · Microsoft Excel MVP
Do you have a specific file or process to improve? Explore Excel consulting →
How to Use the COUNTIFS Function with a Date Range

The COUNTIFS function can also count how many Excel cells fall within a certain date range, but it requires a specific notation to work.
For example, what would we do if we wanted to know how many subscriptions were sold during a certain period?
In this case, you would need to filter the rows where the subscription start and end dates fall between two specific dates, specified in cells R3 and S3:
=COUNTIFS(TBL[START],">="&R3,TBL[END],"<="&S3)
This formula clearly shows how to write an inequality condition correctly.
The COUNTIFS function generally accepts the following as criteria:
- cells (as in the previous example), for example (range,H3,range2,J3...)
- strings containing the condition to be met, for example ">=9" or "<8". The limitation here is scalability, as this will not allow us to easily update the conditions
- a combination of these two, that is, an inequality symbol enclosed in quotation marks and a cell that can change dynamically.
This last option is undoubtedly the most interesting because it allows you to write the inequality dynamically.
Keep in mind that an inequality written this way consists of three parts:
- The first part contains the quotation marks and the inequality symbol, for example ">="
- The second part is always the “&” symbol, which is used to link the inequality symbol to the cell value
- The third part is the value against which the inequality must be checked, indicated, however, by a cell reference.
For example:
">="&R3
The advantage of writing the inequality this way is clearly evident in our example.
In fact, by writing two separate inequalities, we can filter for dates after February 1, 2023, and at the same time, before May 1, 2024.
This notation is very useful when working with time intervals, but not only then, as we’ll see.
How to use the COUNTIFS function with a range of numbers

With the COUNTIFS function, we might want to count, for example, the numbers within a certain range in Excel. This can be very convenient when aggregating data, such as “How many customers spent between 500 and 2,000 €?” and similar questions.
In this case, let’s look at a similar scenario: how many cells contain a number of entries greater than 40 and up to 70?
The solution is similar to the one we saw for dates, since the formula will always contain an inequality condition on the lower end of the range and one on the upper end of the range:
=COUNTIFS(TBL[No. of Enrollments],">"&V3,TBL[No. of Enrollments],"<="&W3)
The conditions could be further combined, for example by filtering exclusively for PESCARA, as we saw earlier, simply adding another criteria range would allow us to make our calculations even more specific. Note that in this case, the result is 2 because there is a cell with 70 entries, if the second condition were "<"&W3, this value would not be considered. Be careful because, when working with ranges, this is a crucial point to avoid duplicates.
Why Use the COUNTIFS Function
The COUNTIFS function is a fundamental Excel function that can be useful in many situations. Although it’s possible to use up to 127 conditions, it’s always preferable to organize functions and data effectively from a logical standpoint, rather than taking the brute-force approach and entering 127 conditions. As we’ve seen, this function can be used in several ways:
- In text-based cases, simply enter the range in question and a cell reference containing the desired text
- For text-based cases, enter a wildcard to find cells containing a specific string, such as "*"&...&"*"
- For numerical cases, enter a specific number or date
- For numeric cases, enter a range of dates or numbers using ">="& and so on
In Excel for Microsoft 365, if you want the count for every location at once instead of writing one COUNTIFS per value, GROUPBY does it with a single formula: =GROUPBY(TBL[LOCATIONS],TBL[LOCATIONS],COUNTA). It lists each location with its number of rows, plus a grand total, and updates when the data changes. See the guide to GROUPBY in Excel.
Conclusion
COUNTIFS counts the rows that meet one or more conditions on text, words contained in a cell, dates or number ranges. Together with SUMIFS, it is the base of most summary reports in Excel.
If you want to follow the step-by-step guide, download the file containing all the examples we've gone over together
