TOTAL |
The TOTAL function calculates the total of the values of an expression.
Return Value
The data type of the expression. It can be INTEGER, LONGINT, or DECIMAL.
Syntax
TOTAL(expression [dimensions])
Arguments
The expression to be totalled.
The dimensions of the result. By default, TOTAL returns a single value. When you indicate one or more dimensions for the results, TOTAL calculates a total for each value of 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. When it is a related dimension, you can specify the name of the relation instead of the dimension name. This enables you to choose which relation is used when there is more than one.
Notes
How TOTAL Handles NA Values
TOTAL is affected by the NASKIP option. When NASKIP is set to YES (the default), TOTAL ignores NA values and returns the sum of the values that are not NA. When NASKIP is set to NO, TOTAL returns NA when any value in the calculation is NA. When all data values for a calculation are NA, TOTAL returns NA for either setting of NASKIP.
Totaling over a DWMQY Dimension
When expression is dimensioned by a dimension of type DAY, WEEK, MONTH, QUARTER, or YEAR, you can specify any other DAY, WEEK, MONTH, QUARTER, or YEAR dimension as a related dimension. Oracle OLAP uses the implicit relation between the dimensions. To control the mapping of one DAY, WEEK, MONTH, QUARTER, or YEAR dimension 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 TOTAL function.
For each time period in the related dimension, Oracle OLAP totals 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 time dimensions, you can use the TCONVERT function.
Multiple Relations in a TOTAL Function
When you break out the total by a related dimension, you are changing the dimensionality of the expression, so Oracle OLAP expects values based on this new dimensionality. It chooses the relation that holds values of that dimension.
When there is more than one relation that holds values of the expected dimension, Oracle OLAP uses the one that was defined first. When there is no relation in which the related dimension is the one expected, Oracle OLAP looks for a relation that is dimensioned by the expected dimension.
For example, assume that there are two relations between district and region, as follows.
DEFINE REGION.DISTRICT RELATION REGION <DISTRICTGREATERTHAN LD The region each district belongs to DEFINE DISTRICT.REGION RELATION DISTRICT <REGIONGREATERTHAN LD The primary district in each region
When a workspace had the two relations described earlier and you specified the following TOTAL function, Oracle OLAP would use the relation region.district by default, because it holds values of the specified dimension.
REPORT TOTAL(sales region)
Examples
Totaling Sales over All Months
Suppose you would like to see the total sportswear sales for all months for each district. Use the TOTAL function to calculate the total sales. To see a total for each district, specify district as the dimension of the results.
LIMIT product TO 'Sportswear' REPORT W 15 HEADING 'Total Sales' TOTAL(sales district)
The preceding statements produce the following output.
DISTRICT Total Sales -------------- --------------- Boston 1,659,609.90 Atlanta 3,628,616.62 Chicago 2,296,631.81 Dallas 3,893,829.30 Denver 2,133,425.29 Seattle 1,298,215.59