Oracle® OLAP DML Reference 10g Release 2 (10.2) Part Number B14346-02 |
|
|
View PDF |
The AVERAGE function calculates the average of the values of an expression.
Return Value
DECIMAL
Syntax
AVERAGE(expression [dimension ...] )
Arguments
The expression whose values are to be averaged.
The name of a dimension of the result; or, the name of a relation between one of the dimensions of expression and another dimension that you want as a dimension of the result.
By default, AVERAGE returns a single value. When you indicate one or more dimensions for the result, AVERAGE calculates values along the dimensions that are specified and returns an array of values. Each dimension must be either a dimension of expression or related to one of its dimensions.
Tip:
When you specify a dimension that is not an actual dimension of expression, but, instead, is dimension that is related to a dimension of expression and when there is more than one relation between the two dimensions, Oracle OLAP uses the default relation between the dimensions to perform the calculation. (See the RELATION command for more information on default relations.) When you do not want Oracle OLAP to use this default relation, specify the related dimension by specifying the name of a specify relation.Notes
NA Values and AVERAGE
AVERAGE is affected by the NASKIP option in the same manner as other aggregate functions. When NASKIP is set to YES
(the default), AVERAGE ignores NA
values and returns the average of the values that are not NA
. When NASKIP is set to NO
, AVERAGE returns NA
when any value of the expression is NA
. When all the values of the expression are NA
, AVERAGE returns NA
for either setting of NASKIP.
Averaging Over a Dimension of Type DAY, WEEK, MONTH, QUARTER, or YEAR
When expression is dimensioned by a dimension of type DAY, WEEK, MONTH, QUARTER, or YEAR, you can specify any other dimension that has one of these types as a related dimension. Oracle OLAP uses the implicit relation between the two dimensions. To control the mapping of one of these types of dimensions to another (for example, from weeks to months), you can define an explicit relation between the two dimensions and specify the name of the relation as the dimension argument to the AVERAGE function.
For each time period in the related dimension, Oracle OLAP averages the data for all the source time periods that end in the target time period. This method is used regardless of which dimension has the more aggregate time periods. To control the way in which data is aggregated or allocated between the periods of two dimensions, you can use the TCONVERT function.
Examples
Example 10-12 Calculating Average Monthly Sales
This example shows how to calculate the average monthly sales of sportswear for each sales district.
LIMIT product TO 'SPORTSWEAR' REPORT W 14 HEADING 'Average Sales' AVERAGE(sales district)
The preceding statements produce the following output.
DISTRICT Average Sales ----------- -------------- Boston 69,150.41 Atlanta 151,192.36 Chicago 95,692.99 Dallas 162,242.89 Denver 88,892.72 Seattle 54,092.32
You might also want to see the average monthly sales for each region. Since the region
dimension is related to the district
dimension, you can specify region
instead of district
as a dimension for the results of AVERAGE.