Quick Answer

DATABASE Function

D-functions calculate on database rows that match a criteria range, using a shared (database, field, criteria) signature.

✓ Excel✓ Google SheetsExcel All versions

Syntax

DATABASE
(database, field, criteria)

Parameters

ParameterDescriptionRequired
databaseThe range of cells that makes up the list or database, including the header row as its first row. Each column is a field and each following row is a record.Required
fieldThe column to use in the calculation. Supply the column label in quotes (e.g. "Yield") or the column's 1-based position within the database (e.g. 4).Required
criteriaThe range of cells that contains the conditions, including a header row that matches database column names and at least one condition row beneath it. A record matches only if it satisfies every condition in a given criteria row; multiple criteria rows are treated as OR.Required

Basic Example

Sum the Yield of apple trees taller than 10 using the shared D-function pattern

=DSUM(A1:E7, "Yield", A9:B10)
Result24

The criteria range A9:B10 holds Tree = Apple and Height > 10; only two records match (Yield 14 and 10), which sum to 24.

Advanced Examples

Example 1: How the criteria range works

A small orchard table

The database is A1:E7 with headers Tree, Height, Age, Yield, Profit. The criteria block A9:B10 reuses two of those headers so the function knows which columns to filter on.

=DAVERAGE(A1:E7, "Yield", A9:B10)
Result: 12
Matching rows have Yield 14 and 10, so the average is (14+10)/2 = 12. The criteria headers must exactly match database headers for the filter to apply.

Example 2: Multiple criteria rows act as OR

Find tall apples OR any cherry tree

Build a criteria range with two condition rows: row one is Tree=Apple, Height>10; row two is Tree=Cherry. Records matching either row are included.

=DCOUNT(A1:E7, "Yield", A9:B11)
Result: 3
Two tall apples plus the single cherry record match, giving a count of 3 numeric Yield values.

How DATABASE Works

Each D-function first filters the database rows so that only records matching the criteria range remain. It then applies its specific calculation (sum, average, count, max, min, product, or a statistic) to the values in the specified field column of those matching records. Filtering uses the same rules as Excel's advanced filter: criteria on the same row are AND-ed, criteria on different rows are OR-ed, and operators such as >, <, >=, <=, <>, and wildcards (*, ?) are supported.

1
Build the database
Put your data in a range with a header row of unique column names, one record per row.
2
Build the criteria range
Copy the column header(s) you want to filter on to a separate area and type the condition(s) below them.
3
Write the D-function
Call =DFUNC(database, "Field", criteria) with the field name in quotes or its column index.

Important Notes & Limitations

  • The criteria header labels must exactly match the database headers or the condition is ignored.

  • Field names with spaces or special characters must be quoted; an unquoted bare column name in the formula will error.

  • DCOUNT only counts numeric cells, while DCOUNTA counts any non-blank cell, so they can return different results.

Common Errors & Fixes

#VALUE!The field argument is a text column name not enclosed in quotes, or the criteria range has no header.

Fix: Wrap the field name in double quotes and ensure the criteria range includes a header row.

Wrong or zero resultCriteria headers do not match database headers, so no rows are filtered.

Fix: Make the criteria header text identical to the database column name.

Download Practice File

Practice DATABASE with Real Data

Download a sample CSV file with pre-populated data and practice exercises for the DATABASE function. Works in both Excel and Google Sheets.

Works in Google SheetsCompatible with ExcelIncludes exercises

File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps

Frequently Asked Questions

What is the difference between field as text and as a number?
You may pass the column label in quotes, e.g. "Yield", or its 1-based position, e.g. 4. Both refer to the same column.
How do I filter on more than one column?
Add more condition columns to the criteria range, each with a matching header. Conditions on the same row are AND-ed; additional rows are OR-ed.
Which D-function should I use to count matches?
Use DCOUNT to count numeric matches and DCOUNTA to count any non-blank matches; use DGET to pull a single value when exactly one record matches.