DBCount Function

The DBCount function returns the number of rows in a table. The rows that are included can be limited by applying a filter

This function can be added to your worksheet by using the Function Wizard.


DBCount( Connection , Table , filter , [ parameter1 ] , [ ...parameter n ] )

The DBCount function syntax has these parts:

connectionRequired. This argument identifies the connection name used to connect to the database.
tableRequired. This argument identifies an SQL statement or a specific internal table name in the database. If this argument does not supply a valid source of data, then the result of the function will be #TABLE? ("table name" not found).
columnRequired. This argument identifies an internal field name or alias returned by the table name argument. Specifying a field will result in a distict count for the field. Specifying "*" as the argument will result a count of all records. If this argument does not contain a valid field name, then the result of the function will be #FIELD? ("field name" not found).
filterOptional. A filter is a string of text that includes comparisons between fields in the table and specific values as a literal value or a parameter.
Parameters to a cell reference are indicated by using a question mark placeholder within the filter string. The function will evaluate the question mark placeholder with the corresponding parameter.
Only the records that satisfy the filter conditions will be used to return values.
parameter 1 , [ ...parameter n ]Required if filter uses placeholders. This is a comma-delimited list of values or cell references used to replace the corresponding question mark placeholders within the filter string. Parameter 1 is used for the first question mark placeholder in the filter, Parameter 2 would represent the second question mark placeholder, and so on.

DBCount Example

Returns the a count of distinct invoices for the vendor specified in cell A5.

=DBCount("Sage 100 Contractor", "acpinv", "invnum", "vndnum=?", A5)

For a video demonstration of implementing this function, check our
 Recorded Training