Application.DAvg (Access)

You can use the DAvg function to calculate the average of a set of values in a specified set of records (a domain).

For example, you could use the DAvg function in the criteria row of a select query on freight cost to restrict the results to those records where the freight cost exceeds the average. Or you could use an expression including the DAvg function in a calculated control and display the average value of previous orders next to the value of a new order. Records containing Null values aren't included in the calculation of the average. Whether you use the DAvg function in a macro or module, in a query expression, or in a calculated control, you must construct the Criteria argument carefully to ensure that it will be evaluated correctly. You can use the DAvg function to specify criteria in the Criteria row of a query. For example, suppose you want to view a list of all products ordered in quantities above the average order quantity. You could create a query on the Orders, Order Details, and Products tables, and include the Product Name field and the Quantity field, with the following expression in the Criteria row beneath the Quantity field:

DAvg (Expr, Domain, Criteria)


>DAvg("[Quantity]", "Orders")

Arguments

The following arguments are required:

Expr (String) - An expression that identifies the field containing the numeric data that you want to average. It can be a string expression identifying a field in a table or query, or it can be an expression that performs a calculation on data in that field. In Expr_, you can include the name of a field in a table, a control on a form, a constant, or a function. If Expr includes a function, it can be either built-in or user-defined, but not another domain aggregate or SQL aggregate function.

Domain (String) - A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.

Optional arguments

The following argument is optional

Criteria (String) - An optional string expression used to restrict the range of data on which the DAvg function is performed. For example, Criteria is often equivalent to the WHERE clause in an SQL expression, without the word WHERE. If Criteria is omitted, the DAvg function evaluates Expr against the entire domain. Any field that is included in Criteria must also be a field in Domain; otherwise, the DAvg function returns a Null.