Skip to content

COUNTIFS

Counts the rows that meet two or more conditions at once, such as late orders from one warehouse.

Syntax

=COUNTIFS(, , [criteria_range2, criteria2], ...)

Statistical

Excel 2007 and later, including Excel for Microsoft 365 and Excel for the web.

Try it

Edit the formula in B13 or change the inputs. The sheet recalculates as you type.

B13
A
B
C
1
Warehouse
Status
Days late
2
Leeds
Shipped
0
3
Leeds
Late
3
4
Bristol
Late
5
5
Leeds
Shipped
0
6
Bristol
Shipped
0
7
Bristol
Late
2
8
Leeds
Late
8
9
Bristol
Shipped
0
10
Leeds
Late
1
11
Bristol
Shipped
0
12
13
Late from Leeds
3

B13 =COUNTIFS(A2:A11,"Leeds",B2:B11,"Late") returns 3

How COUNTIFS works

COUNTIFS counts the rows where every condition is true. It extends COUNTIF to questions like "how many late orders came from Leeds?" or "how many deals over 8,000 are qualified?".

How it works

Each condition is a pair: a range to test and a criterion to test it with. Excel checks the first pair on every row, then the second, and counts a row only when all pairs pass.

=COUNTIFS(A2:A11, "Leeds", B2:B11, "Late")

The ranges can be in different columns, but they must have exactly the same number of rows and columns. If they differ, COUNTIFS returns #VALUE!.

Conditions on the same column

You can test one column twice to build a range. To count days late from 1 to 5 inclusive:

=COUNTIFS(C2:C11, ">=1", C2:C11, "<=5")

The same approach counts dates between two dates held in cells: =COUNTIFS(B2:B11,">="&F1,B2:B11,"<="&F2).

Criteria rules

Criteria work as they do in COUNTIF: a bare value means equals, comparisons go in quotes with the operator (">3", "<>Shipped"), wildcards * and ? work on text, and a cell reference reads its current value. Use "<>" for non-blank and "" for blank.

AND logic only

All the conditions are joined with AND. For OR logic, add two COUNTIFS results, taking care not to double-count rows that meet both, or use SUMPRODUCT:

=SUMPRODUCT(((A2:A11="Leeds")+(A2:A11="Bristol")>0)*(B2:B11="Late"))

An array of criteria also works: =SUM(COUNTIFS(A2:A11,{"Leeds","Bristol"},B2:B11,"Late")) adds the counts for each warehouse.

Alternatives

For a single condition, COUNTIF is shorter. To total the matching numbers, use SUMIFS. To average them, use AVERAGEIFS. To find the largest or smallest, use MAXIFS or MINIFS.

COUNTIFS is a good building block for a summary table: put the row labels in one column and the column labels in a header row, then use a mixed reference formula such as =COUNTIFS($A$2:$A$11,$E2,$B$2:$B$11,F$1) and fill it across and down.

Arguments

criteria_range1
The first range to test, such as A2:A11.
criteria1
The first condition: a value, a cell reference, or an expression such as ">3", "<>Shipped" or "Lee*". Text and operators go in quotes.
criteria_range2, criteria2, ...optional
More pairs of range and condition, up to 127 pairs. Every range must be the same size and shape as the first.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Two text conditions

B13 =COUNTIFS(A2:A11,"Leeds",B2:B11,"Late")

Result: 3

Rows 3, 8 and 10 are both from Leeds and Late.

B13
A
B
C
1
Warehouse
Status
Days late
2
Leeds
Shipped
0
3
Leeds
Late
3
4
Bristol
Late
5
5
Leeds
Shipped
0
6
Bristol
Shipped
0
7
Bristol
Late
2
8
Leeds
Late
8
9
Bristol
Shipped
0
10
Leeds
Late
1
11
Bristol
Shipped
0
12
13
Late from Leeds
3

B13 =COUNTIFS(A2:A11,"Leeds",B2:B11,"Late") returns 3

Example 2

A text condition and a numeric one

B13 =COUNTIFS(B2:B11,"Late",C2:C11,">3")

Result: 2

Only the 5-day and 8-day orders are late by more than 3 days.

B13
A
B
C
1
Warehouse
Status
Days late
2
Leeds
Shipped
0
3
Leeds
Late
3
4
Bristol
Late
5
5
Leeds
Shipped
0
6
Bristol
Shipped
0
7
Bristol
Late
2
8
Leeds
Late
8
9
Bristol
Shipped
0
10
Leeds
Late
1
11
Bristol
Shipped
0
12
13
Late by more than 3 days
2

B13 =COUNTIFS(B2:B11,"Late",C2:C11,">3") returns 2

Example 3

A range built from two conditions on one column

B13 =COUNTIFS(C2:C11,">=1",C2:C11,"<=5")

Result: 4

The same column is tested twice. Days late of 3, 5, 2 and 1 fall in the range.

B13
A
B
C
1
Warehouse
Status
Days late
2
Leeds
Shipped
0
3
Leeds
Late
3
4
Bristol
Late
5
5
Leeds
Shipped
0
6
Bristol
Shipped
0
7
Bristol
Late
2
8
Leeds
Late
8
9
Bristol
Shipped
0
10
Leeds
Late
1
11
Bristol
Shipped
0
12
13
Late by 1 to 5 days
4

B13 =COUNTIFS(C2:C11,">=1",C2:C11,"<=5") returns 4

Example 4

Conditions read from cells, with "not equal"

B14 =COUNTIFS(A2:A11,B13,B2:B11,"<>Shipped")

Result: 2

Bristol has two orders that are not shipped. Type Leeds into B13 and the answer becomes 3.

B14
A
B
C
1
Warehouse
Status
Days late
2
Leeds
Shipped
0
3
Leeds
Late
3
4
Bristol
Late
5
5
Leeds
Shipped
0
6
Bristol
Shipped
0
7
Bristol
Late
2
8
Leeds
Late
8
9
Bristol
Shipped
0
10
Leeds
Late
1
11
Bristol
Shipped
0
12
13
Warehouse
Bristol
14
Not yet shipped
2
15

B14 =COUNTIFS(A2:A11,B13,B2:B11,"<>Shipped") returns 2

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In F2, count the qualified leads that came from the source named in E2.

Answer in F2.

F2
A
B
C
D
E
F
1
Source
Stage
Value
Source
Count
2
Web
Qualified
5,000
Web
3
Event
Qualified
8,000
4
Web
Lost
2,000
Qualified, 8,000 or more
5
Referral
Qualified
12,000
6
Event
Lost
3,000
7
Web
Qualified
7,000
8
Referral
Lost
4,000
9
Web
Qualified
15,000
10

Common mistakes

  • #VALUE! means the criteria ranges are different sizes. Make every range start and end on the same rows.
  • All conditions must be true. COUNTIFS cannot do "Leeds or Bristol" in one pair; add two counts together, or use an array constant inside SUM.
  • A bare number is an equality test. COUNTIFS(C2:C11,3) counts cells equal to 3, not above 3. Put operators in quotes: ">3".
  • A cell reference in quotes, such as "B13", is treated as the text B13. Write B13, or ">"&B13 to combine an operator with a cell.
  • Dates compare as numbers. A date typed as text will not match a numeric comparison. Convert it with DATEVALUE or re-enter it as a real date.

Questions people ask

What is the difference between COUNTIF and COUNTIFS?

COUNTIF takes one range and one condition. COUNTIFS takes any number of range and condition pairs, and counts rows that satisfy all of them. COUNTIFS also works with one condition.

How do I count with OR conditions?

Add separate counts, such as `=COUNTIFS(A2:A11,"Leeds",B2:B11,"Late")+COUNTIFS(A2:A11,"Bristol",B2:B11,"Late")`, or use an array constant: `=SUM(COUNTIFS(A2:A11,{"Leeds","Bristol"},B2:B11,"Late"))`.

How do I count between two dates?

Test the date column twice: `=COUNTIFS(B2:B11,">="&F1,B2:B11,"<="&F2)`, where F1 and F2 hold the start and end dates.

Why does COUNTIFS return 0 when I can see matches?

The data probably has extra spaces, numbers stored as text, or a mismatch in spelling. Check the cells with LEN, and clean them with TRIM or VALUE.

How many conditions can COUNTIFS take?

Up to 127 pairs of range and criteria.

Learn COUNTIFS in a real sheet.

COUNTIFS is taught in Data analysis with formulas, lesson 2: COUNTIFS and AVERAGEIFS. Each lesson is a short, graded exercise like the one above.