The category table of ECMA-376 5th edition Part 1 (December 2016) section 18.17.7 lists twelve database functions: DAVERAGE, DCOUNT, DCOUNTA, DGET, DMAX, DMIN, DPRODUCT, DSTDEV, DSTDEVP, DSUM, DVAR and DVARP. All take the same three arguments. Only DAVERAGE (18.17.7.77) describes them in full; the other eleven refer to it. This page gives the arguments and the criteria range rules once, then each function with the standard’s example, then [MS-OI29500] v20260818’s notes on what Office does differently, then what LibreOffice returns. Section numbers are the standard’s own.
How the examples were checked
The standard’s example table (a criteria range in A1:F3, a database in A4:E10) and 58 edge cases were
written as formulas in a flat ODS workbook, made by samples/xlsx/oracle/make-fods.mjs from
formulas.txt, and converted to CSV by LibreOffice (soffice --headless --convert-to
csv; files in samples/xlsx/oracle/dbfn/). LibreOffice turns wildcards on when it opens an XLSX and off in
a flat ODS, so the same 61 formulas were also written into a real XLSX with
samples/xlsx/oracle/dbfn/make-xlsx.mjs (formula cells without cached values) and converted the same
way; the two CSVs differ only where a criterion uses * or ? (see below). The numbers
on this page marked “LibreOffice” come from the XLSX run. LibreOffice is an implementation, not the
standard: where it differs the difference is reported, not corrected. Its errors appear in its own spellings:
Err:502 (invalid argument), Err:504 (error in the parameter list).
The example data, as the standard gives it:
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Tree | Height | Height | |||
| 2 | =Apple | >10 | <16 | |||
| 3 | =Pear | |||||
| 4 | Tree | Height | Age | Yield | Profit | |
| 5 | Apple | 18 | 20 | 14 | 105.00 | |
| 6 | Pear | 12 | 12 | 10 | 96.00 | |
| 7 | Cherry | 13 | 14 | 9 | 105.00 | |
| 8 | Apple | 14 | 15 | 10 | 75.00 | |
| 9 | Pear | 9 | 8 | 8 | 76.80 | |
| 10 | Apple | 8 | 9 | 6 | 45.00 |
Arguments (18.17.7.77)
Every database function is NAME ( database , field , criteria ).
| Name | Type | Meaning (standard) |
|---|---|---|
database | reference | The range that makes up the list or database: related rows are records, columns are fields. The first row of the list shall contain a label for each column. |
field | text or number | Which column. Either a string holding the column’s label or the column’s position number, counted from 1. [Example: if column 3’s label is “Age” either 3 or “Age” can be used.] |
criteria | reference | The range that holds the conditions. It shall include at least one column label and at least one cell below the label in which a condition for that column is specified. It shall not overlap the database range. |
What a condition can be
Each condition cell shall hold a number, an expression, a cell reference or text that defines which cells are
selected. In text, ? matches any single character and * any sequence;
~ in front of ?, * or ~ matches that character itself. A
text condition can start with a comparison operator followed by the operand. If the text does not begin with
an operator it matches any string that starts with that text, as if * were appended: “Pea”
matches Pea, Pear and Peach, “=Pea” matches only Pea. The standard adds that comparison operators
need no prefix inside the string, and that one cannot search for a string that itself begins with an
operator.
How rows combine
- Several conditions for one column: the standard says they “shall be specified directly below one
another in separate rows”; a record is chosen when it meets the conditions of any one of those rows
(the example
A1:A3with =Apple and =Pear selects both kinds of tree). - Conditions in the same row of the criteria range, on different columns: all must hold (AND).
- Conditions in different rows: any row may hold (OR). Each row is a separate set of conditions.
- A set that needs two conditions on one column (for example a height above 10 and below 16): repeat the column heading in the criteria range, as F1 does in the example.
- To act on the whole column, leave a blank line below the labels in the criteria range (“a blank line shall be entered below the column labels in the criteria range”).
LibreOffice agrees: DMAX(A4:E10,"Profit",A1:A3) (rows =Apple and =Pear) gives 105 and
DSTDEV over the same criteria 2.97, so the rows are alternatives.
Excel note (MS-OI29500 2.1.921, 925, 926, 932, 934, 935, 939 to 942, 944 and 945): the
standard says field is the column to which the criteria are applied; Office treats it as the
column whose values are averaged, counted, summed, multiplied, searched for the maximum or minimum, or used
for the deviation or variance. The criteria are applied by the labels in the criteria range, not by
field. The examples below agree with Office’s reading.
The twelve functions
| Function | Returns (standard) | Standard’s example | LibreOffice |
|---|---|---|---|
DAVERAGE (.77) | number: the average of the values in the column that match | DAVERAGE(A4:E10,"Yield",A1:B2) = 12; DAVERAGE(A4:E10,3,A4:E10) = 13 (the criteria range is the whole database, so every row matches) | 12; 13 |
DCOUNT (.81) | number: how many cells in the column hold numbers | DCOUNT(A4:E10,"Age",A1:F2) = 1 | Err:504 for A1:F2 (blank labels C1:E1, see below); 1 when C1:E1 are labelled |
DCOUNTA (.82) | number: how many cells in the column are not blank | DCOUNTA(A4:E10,"Profit",A1:F2) = 1 | Err:504 for A1:F2; 1 when C1:E1 are labelled |
DGET (.90) | the value of the one matching cell; #VALUE! if no record matches, #NUM! if more than one | DGET(A4:E7,"Yield",A1:A2) = 14 (the standard’s text calls this “the number of Profit fields that are not blank”, copied from DCOUNTA: a slip) | 14; no match #VALUE!; two matches Err:502 (not #NUM!); a text field returns the text (Cherry) |
DMAX (.92) | number: the largest value | DMAX(A4:E10,"Profit",A1:A3) = 105 | 105 |
DMIN (.93) | number: the smallest value | DMIN(A4:E10,"Profit",A1:B2) = 75 | 75 |
DPRODUCT (.97) | number: the product | DPRODUCT(A4:E10,"Yield",A1:B2) = 140 | 140 |
DSTDEV (.98) | number: the sample standard deviation | DSTDEV(A4:E10,"Yield",A1:A3) = 2.97 | 2.96647939483827 |
DSTDEVP (.99) | number: the standard deviation of the whole population | DSTDEVP(A4:E10,"Yield",A1:A3) = 2.65 | 2.65329983228432 |
DSUM (.100) | number: the sum | DSUM(A4:E10,"Profit",A1:A2) = 225; DSUM(A4:E10,"Profit",A1:F2) = 75 | 225; Err:504 for A1:F2 (blank labels); 75 when C1:E1 are labelled |
DVAR (.102) | number: the sample variance | DVAR(A4:E10,"Yield",A1:A3) = 8.8 | 8.8 |
DVARP (.103) | number: the population variance | DVARP(A4:E10,"Yield",A1:A3) = 7.04 | 7.04 |
All twelve examples of the standard were reproduced, with the one condition that the criteria range A1:F2 has labels in every column. The standard’s own example leaves C1:E1 blank, which is a case where LibreOffice differs (next section). The numbers 2.97, 2.65, 8.8 and 7.04 are the standard’s rounded figures: the Yield values of the apple and pear rows are 14, 10, 8, 10, 6, with mean 9.6.
Edge cases and LibreOffice differences
The standard does not say what happens in these cases. The middle column is LibreOffice on the example data, with the formulas of samples/xlsx/oracle/dbfn/formulas.txt.
| Case | LibreOffice (XLSX run) | Against the standard |
|---|---|---|
| Criteria range with blank labels, such as A1:F2 whose C1:E1 are empty (DCOUNT, DCOUNTA, DSUM above) | Err:504 | The standard’s own examples use exactly this range and give 1, 1 and 75. With the labels filled in (AC1:AH2: Tree, Height, Age, Yield, Profit, Height) the results are 1, 75 and 1. This is a difference to report: LibreOffice rejects a blank label cell in the criteria range. |
A condition without an operator: Pea (rows Pear) | 0 (no prefix match; Pea means exactly Pea) | The standard says it matches any string starting with the text, which would give the Pear rows (172.8). Difference. |
Wildcards P*r and A?ple | XLSX open: 172.8 and 225 (wildcards on). Flat ODS: 0 and 0 (off) | The standard applies wildcards. LibreOffice follows it on XLSX import only. |
| An empty condition cell below the label (all rows) | 502.8, the sum of all profits | As the standard says. |
Comparison conditions: >=10 on Yield; <>Apple; =Pea | 276; 277.8; 0 | As the standard says (=Pea matches only Pea). |
| A numeric condition (Height 12) | 96 (the Pear row) | Number conditions are allowed. |
Case of the condition text (apple) and of field ("profit") | 225 and 225: not case-sensitive | The standard does not say. |
field as a number; as a fraction (4.9); as a cell holding the label | 3 gives the third column; 4.9 gives the fourth (30, the apple yields 14+10+6); a cell reference to the label works | The standard gives only whole numbers and the label text. |
field that is not a label ("Nope") or 0 | Err:504 | The standard does not say. |
field greater than the number of columns (6) | #VALUE! | The standard does not say. |
| A criteria column whose label is not in the database | Err:504 | The standard does not say. |
| No record matches | DAVERAGE #DIV/0!; DCOUNT, DMAX, DMIN, DPRODUCT, DSUM 0; DGET #VALUE! | Only DGET is defined (#VALUE!). |
| One matching record | DSTDEV and DVAR #NUM!; DSTDEVP and DVARP 0 | The standard does not say. |
DCOUNT on a text column ("Tree") | 0 | The standard counts numbers. |
| Database with an empty cell and a text cell in Yield (rows 11 and 12, "n/a") | DCOUNT 6, DCOUNTA 7 (the text counts, the empty cell does not), DSUM 57, DAVERAGE 9.5, DMAX 14, DMIN 6: text and empty cells are skipped | Agrees with the descriptions (“numbers”, “non-blank”). |
| An extra fourth argument, or a missing criteria | Err:504 | The syntax has three arguments. |
The standard’s DGET text says #NUM! when more than one record matches; LibreOffice returns Err:502, an error of its own that it has no standard code for. A file’s cached value comes from the program that saved it.
What the viewer does
The viewer shows the value a cell stores and never recalculates a worksheet. Its conditional-format rules
(explorer/formats/xlsx/cf.js) do not calculate the database functions: a rule that needs one is
reported as not calculated and is not applied.
See also
- Formulas: references, ranges, error values
- Functions: math: SUMIF and COUNTIF, which take one condition
- Functions: lookup and reference
- Sheet features: tables and filters
Not described on this page
- Excel’s own results: only [MS-OI29500] was read; Excel was not run, so the right-hand columns are LibreOffice, not Excel.
- Conditions given as a formula result (a condition cell holding
=">"&B1) and conditions that are dates: not run. - The other categories of 18.17.7: statistical, financial, cube, web and the math functions outside the math page.
Sources
- ECMA-376 5th edition Part 1, research/ooxml/ecma376/p1/part1.txt: category table (line 76966), 18.17.7.77 DAVERAGE (line 80644), .81 DCOUNT (80869), .82 DCOUNTA (80885), .90 DGET (81116), .92 DMAX (81257), .93 DMIN (81278), .97 DPRODUCT (81390), .98 DSTDEV (81410), .99 DSTDEVP (81430), .100 DSUM (81448), .102 DVAR (81583), .103 DVARP (81600)
- [MS-OI29500] v20260818, research/ooxml/ms/MS-OI29500.txt, notes 2.1.921 (line 18712), 925 and 926 (18732 to 18737), 932 (18766), 934 and 935 (18818 to 18823), 939 to 942 (18858 to 18875), 944 and 945 (18924 to 18929)
- LibreOffice, soffice headless, flat ODS and XLSX to CSV: samples/xlsx/oracle/dbfn/