DAVG
Syntax
DAVG (Dimension, {Data}, {Condition})
Description
The DAVG function returns the average of Data for the members in Dimension where Condition is True. If Condition is omitted, DAVG returns the average of Data for all members in Dimension. If Data is omitted, DAVG returns the average of the data cube being calculated, for all members up to the current member in Dimension.
Example
The following examples provide uses of the DAVG function:
Example 1
Suppose an analytic model contains a data cube called ADVERTISING_BY_PRODUCT and a data cube called UNITS_SOLD. Both data cubes use a dimension called PRODUCTS. Use the following formula to calculate the average units sold for all products:
DAVG(PRODUCTS, UNITS_SOLD)
The DAVG function does not include a condition, so the function averages UNITS_SOLD for all members in the PRODUCTS dimension. Use the following formula to calculate the average units sold for all products with advertising of at least USD 10,000:
AVG(PRODUCTS, UNITS_SOLD, ADVERTISING_BY_PRODUCT >= 10000)
In this case, the function averages UNITS_SOLD only for the products where ADVERTISING_BY_PRODUCT is greater than or equal to 10000.
Example 2
You can make the analysis more flexible by creating a dimension called RANGES and attaching it to AVG_UNITS_SOLD. Define a new data cube called AD_COST_MIN that uses the RANGES dimension. Each number in AD_COST_MIN defines the minimum value for the range, while the next number defines the upper limit for the range. Calculate the average units sold for each range as follows:
DAVG(PRODUCTS, UNITS_SOLD, ADVERTISING_BY_PRODUCT >=
AD_COST_MIN .AND. ADVERTISING_BY_PRODUCT <
NEXT(RANGES, AD_COST_MIN))
For each range, the formula averages only those products whose advertising cost is greater than or equal to the current AD_COST_MIN and less than the next AD_COST_MIN. (The NEXT function returns AD_COST_MIN for the next member in the RANGES dimension.)
Related Topics