Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
AGO
This function is a time series aggregation function that calculates the aggregated value from the current time back to a specified time period. For example, AGO can produce sales for every month of the current quarter and the corresponding quarter-ago sales. Time series functions operate on members of time dimensions which are at or below the level of the function. Because of this, one or more columns that uniquely identify members at or below the given level must be projected in the query. Alternatively, you can apply a filter to the query that specifies a single member at or below the given level. If unsupported metrics are requested, NULL values are returned and a warning entry is written to the nqquery.log file when the logging level equals three or above. Multiple AGO functions can be nested if all the AGO functions have the same level argument. You can nest exactly one TODATE and multiple AGO functions if they each have the same level argument.
Syntax
Where:
time_level is an optional argument that specifies the type of time period, such as quarter, month, or year.
offset is an integer literal that represents the time shift amount. Example
If you do not explicitly specify the[time_level] argument, the default level is determined as follows:
If the measure used in the expression is a level-based measure in the time dimension (as set in the Administration Tool), then that same level is considered the default AGO level.
Otherwise, the grain of the measure used in the expression, as determined by the BY clause of the measure shown in the logical request, is the default Ago level.
You can see the default AGO level for a given query in the Logical Request section of the query log.
PERIODROLLING
This function computes the aggregate of a measure over the period starting xunits of time and ending y units of time from the current time. For example, you can use PERIODROLLING to compute sales for a period that starts at a certain quarter before and ends at a certain quarter after the current quarter. Time series functions operate on members of time dimensions which are at or below the level of the function. Because of this, one or more columns that uniquely identify members at or below the given level must be projected in the query. Alternatively, you can apply a filter to the query that specifies a single member at or below the given level.
You cannot nest AGO and TODATE functions within a PERIODROLLING function. Also, you cannot nest PERIODROLLING, FIRST, and LAST functions.
If you embed other aggregate functions (like RANK, TOPN, PERCENTILE, FILTER, or RSUM) inside PERIODROLLING, the PERIODROLLING function is pushed inward. For example, PERIODROLLING(TOPN(measure)) is executed as TOPN(PERIODROLLING(measure)).
Syntax
PERIODROLLING(measure, x ,y [,hierarchy])
Where:
x is an integer that specifies the offset from the current time. Precede the integer with a minus sign (-) to indicate an offset into the past.
y specifies the number of time units over which the function will compute. To specify the current time, enter 0.
hierarchy is an optional argument that specifies the name of a hierarchy in a time dimension, such as yr, mon, day, that you want to use to compute the time window. This option is useful when there are multiple hierarchies in a time dimension, or when you want to distinguish between multiple time dimensions.
If you want to roll back or forward the maximum possible amount, use the keyword UNBOUND. For example, the function PERIODROLLING (measure, -UNBOUND, 0) sums over the period starting from the beginning of time until now.
You can combine PERIODROLLINGand AGGREGATE AT functions to specify the level of the PERIODROLLINGfunction explicitly. For example, if the query level is day but you want to find the sum of the previous and current months, use the following:
Examples
SELECT Month_ID, PERIODROLLING(monthly_sales, -1, 1) SELECT Month_ID, PERIODROLLING(monthly_sales, -UNBOUND, 2) SELECT Month_ID, PERIODROLLING(monthly_sales, -UNBOUND, UNBOUND)
The unit of time (offset) used in the PERIODROLLING function is called the level of the function. This value is determined by the measure level of the measures in its first argument and the query level of the query to which the function belongs. The measure level for the measure can be set in the Administration Tool. If a measure level has been set for the measure used in the function, the measure level is used as the level of the function. The measure level is also called the storage grain of the function.
If a measure level has not been set in the Administration Tool, then the query level is used. The query level is also called the query grain of the function. In the following example, the query level is month, and the PERIODROLLINGfunction computes the sum of the last, current, and next month for each city for the months of March and April:
SELECT year, month, country, city, PERIODROLLING(sales, -1, 1) WHERE month in ('Mar', 'Apr') AND city = 'New York'
When there are multiple hierarchies in the time dimension, you must specify the hierarchy argument in the PERIODROLLING function. For example:
TODATE
This function is a time series aggregation function that aggregates a measure from the beginning of a specified time period to the currently displayed time. For example, this function can calculate Year to Date sales. Time series functions operate on members of time dimensions which are at or below the level specified in the function. Because of this, one or more columns that uniquely identify members at or below the given level must be projected in the query. Alternatively, you can apply a filter to the query that specifies a single member at or below the given level. If unsupported metrics are requested, NULL values are returned and a warning entry is written to the nqquery.log file when the logging level equals three or above.
A TODATE function may not be nested within another TODATE function. You can nest exactly one TODATE and multiple AGO functions if they each have the same level argument.
TODATE is different from the TO_DATE SQL function supported by some databases. Do not use TO_DATE to change to a DATE data type. Instead, use the CAST function.
Syntax
TODATE(expr, time_level)
Where:
Example