COUNTIFS
The COUNTIFS function returns the number of cells in one or more collections that satisfy given conditions (one condition per collection).
COUNTIFS(test-values, condition, test-values…, condition…)
test-values: A collection containing values to be tested. test-values can contain any value.
condition: An expression that compares or tests values and results in the boolean value TRUE or FALSE. Condition can include comparison operators, constants, the ampersand concatenation operator, references and wildcards. You can use wildcards to match any single character or multiple characters in the expression. You can use a ? (question mark) to represent one character, an * (asterisk) to represent multiple characters, and a ~ (tilde) to specify that the following character should be matched rather than used as a wildcard.
test-values…: Optionally include one or more additional collections containing values to be tested. Each test-values collection must be followed immediately by a condition expression. This pattern of test-values, condition can be repeated as many times as needed.
condition…: If an optional collection of test-values is included, an additional expression that results in a boolean TRUE or FALSE. There must be one condition expression following each test-values collection; therefore, this function will always have an even number of arguments.
Notes
Each value in test-values is compared to the corresponding condition. If the corresponding values in each collection meet the corresponding conditional tests, the count is increased by 1.
Examples |
---|
Given the following table: |
A | B | C | D | |
---|---|---|---|---|
1 | Age | Sex | Status | Salary |
2 | 35 | M | M | 71000 |
3 | 27 | F | M | 81000 |
4 | 42 | M | M | 86000 |
5 | 51 | M | S | 66000 |
6 | 28 | M | S | 52000 |
7 | 49 | F | S | 62000 |
8 | 63 | F | M | 89000 |
9 | 22 | M | M | 34000 |
10 | 29 | F | S | 42000 |
11 | 35 | F | M | 56000 |
12 | 33 | M | S | 62000 |
13 | 61 | M | M | 91000 |
=COUNTIFS(A2:A13, “<40”, B2:B13, “=M”) returns 4, the number of males (indicated by an “M” in column B) under the age of forty. =COUNTIFS(A2:A13, “<40”, B2:B13, “=M”, C2:C13, “=S”) returns 2, the number of males who are single (indicated by an “S” in column C) and under the age of forty. =COUNTIFS(A2:A13, “<40”, B2:B13, “=M”, C2:C13, “=M”) returns 2, the number of males who are married (indicated by an “M” in column C) and under the age of forty. =COUNTIFS(A2:A13, “<40”, B2:B13, “=F”) returns 3, the number of females (indicated by an “F” in column B) who are under the age of forty. |