Oracle® OLAP Expression Syntax Reference Release 11.2 E23381-01 |
|
|
PDF · Mobi · ePub |
SUM
returns the total of a selection of values calculated over a Time dimension. You can use the SUM
function to create period-to-date calculations.
The GREGORIAN
relations superimpose the Gregorian calendar on the Time dimension. These relations can be useful for calculations on fiscal and nonstandard hierarchies.
NUMBER
SUM (value_expr) OVER (window_clause)
window_clause::=
[ { DIMENSION dimension_id | HIERARCHY hierarchy_id } ] BETWEEN preceding_boundary | following_boundary [WITHIN { PARENT | LEVEL | GREGORIAN {YEAR | QUARTER | MONTH | WEEK} | ANCESTOR AT { DIMENSION LEVEL dim_level_id | HIERARCHY LEVEL hier_level_id } } ]
preceding_boundary::=
{UNBOUNDED PRECEDING | expression PRECEDING} AND { CURRENT MEMBER | expression {PRECEDING | FOLLOWING} | UNBOUNDED FOLLOWING }
following_boundary::=
{CURRENT MEMBER | expression FOLLOWING} AND { expression FOLLOWING | UNBOUNDED FOLLOWING }
A dimensional expression whose values you want to calculate.
The Time dimension over which the values are calculated using the default hierarchy.
The hierarchy over which the values are calculated. If dimension_id
is used instead, the default hierarchy is used.
The name of a level of dimension_id
.
The name of a level of hierarchy_id
.
The preceding_boundary and following_boundary identify a range of time periods within the group identified by the dimension or hierarchy.
UNBOUNDED
starts with the first period or ends with the last period of the group.
CURRENT MEMBER
starts or ends the calculation at the current time period.
A numeric value identifying a period at a particular distance from the current time period that starts or ends the range.
Identifies the range of time periods used in the calculation. Following are descriptions of the keywords.
Range | Description |
---|---|
LEVEL |
Calculates all time periods at the same level. (Default) |
PARENT |
Calculates time periods at the same level with the same parent. |
GREGORIAN YEAR |
Calculates time periods within the same Gregorian year. |
GREGORIAN QUARTER |
Calculates time periods within the same Gregorian quarter. |
GREGORIAN MONTH |
Calculates time periods within the same Gregorian month. |
GREGORIAN WEEK |
Calculates time periods within the same Gregorian week. |
ANCESTOR |
Includes time periods at the same level and with the same ancestor at a specified level. |
This example calculates the sum of two values, for the current and the following time periods, within a level. The results appear in the Sum column.
SUM(UNITS_CUBE.SALES) OVER (DIMENSION "TIME" BETWEEN 1 PRECEDING AND CURRENT MEMBER WITHIN LEVEL)
Time | Sales | Sum |
---|---|---|
Q1.04 | 146529 | 289599 |
Q2.04 | 143070 | 291362 |
Q3.04 | 148292 | 297820 |
Q4.04 | 149528 | 293135 |
Q1.05 | 143607 | 281703 |
Q2.05 | 138096 | 277049 |
Q3.05 | 138953 | 284015 |
Q4.05 | 145062 | 291881 |
The next example calculates Year-to-Date Sales.
SUM(UNITS_CUBE.SALES) OVER (HIERARCHY TIME.CALENDAR BETWEEN UNBOUNDED PRECEDING AND CURRENT MEMBER WITHIN ANCESTOR AT DIMENSION LEVEL TIME.CALENDAR_YEAR)
Time | Sales | Sales YTD |
---|---|---|
JAN-05 | 12093518 | 12093518 |
FEB-05 | 10103162 | 22196680 |
MAR-05 | 9184658 | 31381338 |
APR-05 | 9185964 | 40567302 |
MAY-05 | 11640216 | 52207519 |
JUN-05 | 16816561 | 69024079 |
JUL-05 | 11110903 | 80134982 |
AUG-05 | 9475807 | 89610789 |
SEP-05 | 12030538 | 101641328 |
OCT-05 | 11135032 | 112776359 |
NOV-05 | 11067754 | 123844113 |