How to Use the DGET and DCOUNT Functions in Google Sheets to Query Structured Database Tables

When searching and extracting data in Google Sheets, users frequently rely on XLOOKUP, INDEX/MATCH, or complex FILTER functions. However, when working with multi-field database tables containing distinct column headers and complex criteria ranges, Google Sheets includes a dedicated suite of built-in Database functions. Among the most useful are DGET (which extracts a single unique value matching specific criteria) and DCOUNT (which counts numeric records matching complex criteria). These functions provide clean, auditable lookup architectures that do not require long, nested formula strings.

Understanding Database Function Architecture (Database, Field, Criteria)

All database functions in Google Sheets share an identical 3-argument syntax structure:

=DGET(database, field, criteria)
=DCOUNT(database, field, criteria)

Key parameters explained:

  • database: The complete tabular range including column header labels (e.g., A1:E100). Column headers are mandatory.
  • field: The column you want to extract or count. This can be specified as a text string matching the header label (e.g., "Salary"), a cell reference containing the label (e.g., D1), or a 1-based column index number (e.g., 4).
  • criteria: A separate reference range containing at least one header label and at least one cell below it defining the filter condition.

Setting Up a Dynamic Criteria Range

The power of database functions lies in using an external criteria range. For example, if your main dataset occupies A1:D50 with headers Department, Employee, Role, and Sales:

  1. Copy headers Department and Role into cells G1:H1.
  2. In cell G2, enter "Finance".
  3. In cell H2, enter "Senior Analyst".

Range G1:H2 now functions as a modular criteria block that can be edited on the fly without modifying your formula.

Using DGET to Retrieve an Exact Record Value

To extract the Sales figure for the employee matching the criteria in G1:H2, enter the following formula:

=DGET(A1:D50, "Sales", G1:H2)

Behavioral rules of DGET:

  • If exactly one row matches the criteria, DGET returns the exact field value.
  • If multiple records match the criteria, DGET returns a #NUM! error, alerting you that the result is ambiguous.
  • If no records match the criteria, DGET returns a #VALUE! error.

Using DCOUNT to Count Numerical Entries Matching Multiple Criteria

To determine how many transactions meet multiple simultaneous conditions—for instance, sales records where the Department is "Retail" and Sales are greater than 5000:

  1. Set up your criteria table in G1:H2 with headers Department and Sales.
  2. Enter Retail in G2 and >5000 in H2.
  3. Enter the formula:
    =DCOUNT(A1:D50, "Sales", G1:H2)

DCOUNT evaluates the range and returns the total count of matching rows containing numerical values in the target field.

Implementing AND vs OR Logic in Criteria Blocks

Database functions support sophisticated boolean logic depending on how your criteria block is arranged:

  • AND Logic (Same Row): When criteria are placed on the same horizontal row, all conditions must be met simultaneously.
    Department: "IT" | Region: "West" (Row 2)
  • OR Logic (Different Rows): When criteria are placed on separate vertical rows, rows matching either condition are processed.
    Department: "IT" (Row 2)
    Department: "Finance" (Row 3)

DGET vs VLOOKUP and XLOOKUP Comparison

Feature DGET VLOOKUP XLOOKUP
Criteria Location Dedicated visual table cell range Inside formula argument Inside formula argument
Multi-Field Matching Native across any number of columns Requires helper columns or concatenate Requires boolean array multiplication
Duplicate Detection Errors automatically on multiple matches Silently returns first match only Silently returns first or last match
Maintenance High visibility; non-technical users can edit cells Requires editing complex formula syntax Requires editing complex formula syntax

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.