Skip to content

COUNTIFS Function in Excel

Math · Updated

Purpose
Count the rows where every one of several conditions is true.
Returns
A whole number. 0 if no row meets all the conditions.
Syntax
fx=COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], …)
Works in
Excel 2007 and later · Microsoft 365 · Google Sheets · LibreOffice Calc

Arguments

ArgumentRequiredWhat it is
criteria_range1YesThe first range to test.
criteria1YesThe condition for the first range. A number, a cell reference, or text in double quotes such as "7A" or ">=80".
criteria_range2, criteria2NoMore range and condition pairs, up to 127 pairs in total. Every range must be the same size as the first one.

Example: count the students in one class at or above a score

A row is counted only when its class in column B equals E2 and its score in column C meets the condition typed in F2. Ava and Dev pass both tests.

G2fx=COUNTIFS(B2:B7, E2, C2:C7, F2)
ABCDEFG
1StudentClassScoreClassScoreCount
2Ava7A827A>=802
3Ben7B91
4Cara7A74
5Dev7A88
6Elif7B67
7Finn7B85

Build your COUNTIFS formula

Fill in the fields with your own cells. The formula updates as you type.

Both conditions must be true in the same row.
Your formula
E2fx=COUNTIFS(A2:A20, "East", B2:B20, ">100")

Counts the rows where A2:A20 meets "East" and B2:B20 meets ">100".

Paste the formula into cell E2 or any empty cell. The coloured parts match the coloured fields. Using a different list separator? Replace the commas with semicolons.

How COUNTIFS works

COUNTIFS reads your ranges side by side, one position at a time. At each position it tests the first range against the first condition, the second range against the second condition, and so on. If every test passes, the count goes up by 1. If any test fails, that position is skipped.

Two points follow from this:

  • The conditions are joined with AND. Class is 7A and score is at least 80. There is no “or” between them.
  • The ranges are matched by position. The third cell of one range is tested together with the third cell of every other range. That is why all ranges must be the same size, and why they should start on the same row.

Arguments come in pairs: a range, then the condition for that range. You can have up to 127 pairs.

Writing the criteria

Each condition uses the same rules as COUNTIF. Numbers and cell references need no quotes. Text and comparison operators go inside double quotes.

Criteria Matches
"7A" Cells equal to 7A. Case is ignored.
">=80" Numbers greater than or equal to 80.
"<>7A" Cells that are not equal to 7A.
"*east*" Text that contains “east” anywhere.
">="&E1 Values greater than or equal to the value in E1.
"" Blank cells.
"<>" Cells that are not blank.

A condition can also live in a cell, operator included. In the example above, F2 holds the text >=80 and the formula refers to F2. Changing the cell to <70 changes the count with no formula edit.

The wildcards are * for any run of characters and ? for one character. A tilde in front, as in "~*", matches the character itself.

More examples

The first four use the example data above, with students in column A, classes in column B and scores in column C.

A text condition and a number condition

=COUNTIFS(B2:B7, "7B", C2:C7, "<70")

returns 1. Elif is the only student in 7B with a score below 70.

Between two bounds

=COUNTIFS(C2:C7, ">=70", C2:C7, "<90")

returns 4, the scores 82, 74, 88 and 85. The same range is tested twice.

A wildcard with a second condition

=COUNTIFS(B2:B7, "7A", A2:A7, "*a*")

returns 2. Ava and Cara are in 7A and have the letter a in their names.

Either of two classes, with a score condition

=SUM(COUNTIFS(B2:B7, {"7A","7B"}, C2:C7, ">=85"))

returns 3. COUNTIFS gives one count per class, 1 and 2, and SUM adds them.

Flag rows that repeat on two columns

=COUNTIFS($A$2:$A$100, A2, $B$2:$B$100, B2)>1

returns TRUE on every row whose pair of values in columns A and B appears more than once.

Tips

  • Every range must have the same number of rows and columns. A mismatch returns #VALUE!.
  • Lock the ranges with dollar signs ($B$2:$B$7) and leave the criteria cells relative when you fill a summary table.
  • A reference to an empty criteria cell is treated as 0, so the count can drop to nothing while you are still filling in the inputs.
  • Two conditions on one column work when both can be true, such as a lower and an upper bound. Two different exact values on one column always return 0.
  • Trailing spaces break text matches. “7A “ with a space is a different value from “7A”.

COUNTIFS or SUMIFS

COUNTIFS and SUMIFS take the same range and condition pairs and apply the same AND logic. The difference is what they return.

Function Returns First argument
COUNTIFS How many rows pass every condition. The first criteria range.
SUMIFS The total of a number column for the rows that pass. The sum range.

To turn a count into a total, put the column to add up in front: =COUNTIFS(B2:B7, "7A") counts the 7A rows, and =SUMIFS(C2:C7, B2:B7, "7A") adds their scores. Dividing the second by the first gives the average for the class.

For a single condition, COUNTIF is shorter and works in every version of Excel. To check a list for repeated rows without a formula, use the find duplicates tool.

Errors and fixes

ErrorWhy it happensFix
#VALUE!The criteria ranges are different sizes, for example B2:B7 and C2:C8.Give every range the same first and last row.
0 resultNo row passes every condition. Two different exact values asked of one column can never both be true.Test each condition alone. For either-or logic, add two COUNTIFS formulas together.
Wrong countA criteria cell is empty. COUNTIFS treats a reference to an empty cell as the value 0.Fill in the criteria cell, or leave that range and condition pair out.
#VALUE!The formula refers to ranges in another workbook that is closed.Open the other workbook, or copy the data into the same file.

Questions

What is the difference between COUNTIF and COUNTIFS?

COUNTIF tests one range against one condition. COUNTIFS takes one or more pairs of range and condition, and counts a row only when every pair is true. With a single pair the two give the same result.

Can COUNTIFS do OR logic?

Not between its conditions, which are always joined with AND. Add separate formulas, or pass a list for one condition and sum the counts: =SUM(COUNTIFS(B2:B7, {"7A","7B"}, C2:C7, ">=85")).

Why does COUNTIFS return #VALUE!?

The ranges do not have the same number of rows and columns. B2:B7 with C2:C8 fails. The ranges can be in separate parts of the sheet as long as they are the same size. A reference to a closed workbook causes the same error.

How do I count between two numbers or dates?

Use the same range twice, once for each bound: =COUNTIFS(C2:C100, ">=70", C2:C100, "<90"). For dates held in cells, write =COUNTIFS(A2:A100, ">="&E1, A2:A100, "<="&F1).

Is COUNTIFS case-sensitive?

No. "7a" and "7A" match. Text conditions accept wildcards: an asterisk for any text and a question mark for one character.

Does COUNTIFS count a row twice if it matches two conditions?

No. Each row is counted once, and only if it meets all the conditions. The result can never be larger than the number of rows in the range.

Related