Skip Headers

Oracle® OLAP DML Reference
10g Release 1 (10.1)

Part Number B10339-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

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 [[STATUS] dimensions])

Arguments

expression

The expression to be totalled.

STATUS

Can be specified when one or more of the dimensions of the result of the function are not dimensions of the expression. (See the description of the dimensions argument.) When you specify the STATUS keyword when this is not the case, Oracle OLAP produces an error.

When one or more of the dimensions of the result of the function are not dimensions of the expression, Oracle OLAP creates a temporary variable to use while processing the function. When you specify the STATUS keyword, Oracle OLAP uses the current status instead of the default status of the related dimensions for calculating the size of this temporary variable. In this situation, the STATUS keyword might be required in order for Oracle OLAP to process the function successfully, or the STATUS keyword might provide a performance enhancement:

When you use TOTAL with the STATUS keyword for an expression that requires going outside of the status for results (for example, with the LEAD or LAG functions or with a qualified data reference), the results outside of the status will be returned as NA.

dimensions

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


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.


Aggregating to Higher Levels

When you specify related dimensions, TOTAL adds the values of an array across one or more of its dimensions to obtain an array with fewer dimensions. Because of this, TOTAL is useful for aggregating data from a lower level of detail to a higher level.


Totaling over a Time 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 <DISTRICT>
LD The region each district belongs to
 
DEFINE DISTRICT.REGION RELATION DISTRICT <REGION>
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

Example 23-28 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