- database - Database range including headers.
- field - [optional] Field name or index to count.
- criteria - Criteria range including headers.
How to use
The Excel DCOUNT function counts matching records in a database using a specified field and criteria. The database argument is a range of cells that includes field headers, field is the name or index of the field to count, and criteria is a range of cells with headers matching those in database.
Using the example above, you can count records where the color is "red" and price is > 10 with these formulas:
=DCOUNT(B7:E14,"Total",B4:E5) // field by name =DCOUNT(B7:E14,4,B4:E5) // field by index =DCOUNT(B7:E14,,B4:E5) // field omitted
Caution: if field is provided to the DCOUNT function, it is only counted when non-blank and numeric. If field contains a text value, or if the field is blank, it will not be counted, even when criteria match.
The criteria can include a variety of expressions. The table below shows some examples:
|Red||Match "red" or "RED"|
|Re*||Begins with "re"|
|10||Equal to 10|
|>10||Greater than 10|
|>12/19/2017||Greater than Dec 19, 2017|
The criteria range for DCOUNT can include more than one row below the headers. When criteria includes more than one row, each row is joined with OR logic, and the expressions in a given criteria row are joined with AND logic.
- DCOUNT will only count numeric values in the given field when criteria match. To count either numbers or text, use DCOUNTA.
- DCOUNT supports wildcards in criteria, the support is not as good as in more modern functions like COUNTIFS.
- Criteria can include more than one row (as explained above),
- The field argument can be supplied as a name in double quotes ("") or as a number representing field index.
- The database and criteria ranges must include matching headers.