Database functions

DCOUNT

Matches all 3 recorded answers

Recorded: 3 workbook cells. How we measure this · See the Rust code

Local names in 40 languages
LanguageName in Excel
ArabicDCOUNT
BulgarianDCOUNT
CzechDPOČET
DanishDTÆL
GermanDCOUNT
GreekDCOUNT
English (Australia)DCOUNT
English (United Kingdom)DCOUNT
English (United States)DCOUNT
SpanishBDCONTAR
EstonianDCOUNT
FinnishTLASKE
FrenchBDNB
HebrewDCOUNT
CroatianDCOUNT
HungarianAB.DARAB
IndonesianDCOUNT
ItalianDCOUNT
JapaneseDCOUNT
KoreanDCOUNT
LithuanianDCOUNT
LatvianDCOUNT
NorwegianDANTALL
DutchDBAANTAL
PolishBD.ILE.REKORDÓW
Portuguese (Brazil)DCOUNT
Portuguese (Portugal)BDCONTAR
RomanianDCOUNT
RussianБСЧЁТ
SlovakDCOUNT
SlovenianDCOUNT
Serbian (Latin)DCOUNT
SwedishDANTAL
ThaiDCOUNT
TurkishVSEÇSAY işlevi
UkrainianDCOUNT
VietnameseDCOUNT
Chinese (Simplified)DCOUNT
Chinese (Hong Kong)DCOUNT
Chinese (Traditional)DCOUNT

Names from Microsoft's support site.

What it does

DCOUNT(database, field, criteria)

DCOUNT(database, field, criteria) selects the records of database that satisfy criteria and returns how many of them hold a number in the column named by field.

With R the set of selected record rows and c the resolved field column:

result = | { r in R : value of cell (r, c) is a Number } |

If field is omitted, the column stage disappears and the function returns |R| — the count of matching records, regardless of what any column contains. That two-mode behaviour is what makes DCOUNT the family's record counter as well as its value counter.

"Is a Number" is a test on the value kind, not a parse. Text that reads as a number is not counted; neither are logicals, blanks, or empty strings.

The selection stage — header matching, AND across a criteria row, OR down the rows, blank criteria cells, and how a criteria expression is parsed — is identical for all twelve database functions and is explained once in the criteria-range mechanism.

Arguments

Three argument slots; the reference implementation declares an arity of exactly 3.

  • database — the header-plus-records range or array.
  • criteria — the header-plus-conditions range or array.

Try it

Input cells (optional)

Example: {"B2": 3, "B3": 4}. A1 holds the formula. Other cells need values before a formula can read them.

Enter a formula, then calculate.

Runs locally in your browser with OneCalc. Its answer may differ from Excel. Use English function names and commas between arguments.

Quirks

Result and edge cases

Returns a Number — a count, so always a non-negative integer.

  • No record matches: 0. DCOUNT never errors on an empty selection.
  • Field omitted: the result is the number of matching records. Combined with an all-blank criteria row (which selects everything), this degenerates to the record count of the database.
  • Text that looks numeric in the field column is not counted. This is the range-scan side of the asymmetry in coercion and lifting.
  • Logicals and blanks in the field column are not counted.
  • Arrays: inline array literals resolve to grids and are accepted; DCOUNT is not a lift kernel.

Errors

ErrorCondition
#VALUE!database or criteria is not a grid or is empty; a database header cell is blank; a criteria header names no database field; a supplied field matches no header, or is a non-integer or out-of-range column index
propagatedAn error value in a header cell, a criteria cell, or a scanned field cell surfaces as that error

How to implement

Notes for implementers

  1. Two code paths, one function. The omitted-field mode short-circuits before any column is read, so a bad field value cannot be diagnosed in that mode — there is nothing to diagnose. Resolve the field only when one was supplied.
  2. Distinguish Missing from Empty carefully. Both are treated as "omitted" here, but they arrive by different routes (an empty call slot versus a reference to a blank cell), and the call model keeps them distinct on purpose. An implementation that collapses them upstream loses the ability to make them differ later if evidence says they should.
  3. Count by value kind, not by convertibility. The whole difference between DCOUNT and DCOUNTA lives in this predicate.
  4. Numeric criteria comparison is not exact double comparison — see the note in the shared mechanism.

Rust code

Show the CalcFunc source of this function

Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.

DCOUNT · 1 lines · calc-func/src/catalogue/database.rs on GitHub
2 dcount "DCOUNT" (3, 3) [R "database", V "field", R "criteria"] |s, a, sv| { database(s, a, sv, Kind::Count) }

Kernels shared with other functions

Argument and result plumbing

No implementation has been published with a Handbook test suite for this function.

Version differences

No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.

Alternatives

Relationships

  • DCOUNTA is the sibling that counts non-blank cells instead of numeric ones. The pair mirrors COUNT and COUNTA exactly: DCOUNT counts numbers, DCOUNTA counts anything present. Both accept an omitted field; no other family member does.
  • DSUM and DAVERAGE run over the same value list. DAVERAGE is DSUM divided by DCOUNT except when the count is zero, where DAVERAGE returns #DIV/0! and DCOUNT returns 0.
  • Nearest modern equivalent: COUNTIFS (and COUNTIF), which take conditions inline instead of as a criteria table. Neither supersedes the other.
  • Confused with: COUNT (no selection stage) and DCOUNTA; and, when the field is omitted, with ROWS, which counts rows without any selection at all.

Named variants

No named variants are recorded yet.

Suggest a correction or contribute an implementation · For agents