MicroStrategy ONE
OLAPCount
Returns the count of the current value, preceding values, and succeeding values as defined in the function arguments. Unlike RunningCount and MovingCount, which can only include values above the current row in the calculation, you can use OLAPCount to include values both above and below the current row in the calculation.
The calculations can be restarted based on attributes defined in the function parameters.
Syntax
OLAPCount<Distinct, Null, OLAPWinStType, OLAPWinStOffset, OLAPWinEndType, OLAPWinEndOffset, BreakBy, SortBy>(Argument)
Where:
Distinctis aTRUE/FALSEparameter that allows you to use all values in the calculation or to calculate using only the unique values. If you defineDistinctto be true, then the parametersNull,OLAPWinStType,OLAPWinStOffset,OLAPWinEndType,OLAPWinEndOffset, andSortByare ignored.Nullis aTRUE/FALSEparameter that defines whether null values are included in the total count.BreakByis the attribute indicating where the calculation restarts.SortByis the attribute or metric by which the data is sorted.OLAPWinStTypedefines the window type for the starting location of the calculation. Select one of the following options, listed by the name of the setting and its correspondingOLAPWinStTypevalue in parentheses:- Top of data set (
0): The calculation starts at the top value as determined by theBreakByandSortByvalues. - Current row (
2): The calculation starts at the current row. Nrows before current row (3): The calculation starts a number of rows before the current row. You define this offset of rows with theOLAPWinStOffsetparameter described below.Nrows after current row (4): The calculation starts a number of rows after the current row. You define this offset of rows with theOLAPWinStOffsetparameter described below.
- Top of data set (
OLAPWinStOffsetdefines the offset of rows from the current row to start the calculation. You can define this offset if theOLAPWinStTypeparameter is defined asNrows before current row (3) orNrows after current row (4).OLAPWinEndTypedefines the window type for the ending location of the calculation. Select one of the following options, listed by the name of the setting and its correspondingOLAPWinEndTypevalue in parentheses:- Bottom of data set (
1): The calculation stops at the bottom value. The top value is determined by theBreakByandSortByvalues. - Current row (
2): The calculation stops at the current row. Nrows before current row (3): The calculation starts a number of rows before the current row. You define this offset of rows with theOLAPWinEndOffsetparameter described below.Nrows after current row (4): The calculation starts a number of rows after the current row. You define this offset of rows with theOLAPWinEndOffsetparameter described below.
- Bottom of data set (
OLAPWinEndOffsetdefines the offset of rows from the current row to stop the calculation. You can define this offset if theOLAPWinEndTypeparameter is defined asNrows before current row (3) orNrows after current row (4).Argumentis a metric representing a list of numbers.
The function is not valid if your starting point is at a lower point than your ending point.
Example
An OLAPCount Unit Cost metric is created using the OLAPCount function based on the Unit Cost metric, as defined below:
OLAPCount<OLAPWinStType=3, OLAPWinStOffset=3, OLAPWinEndType=4, OLAPWinEndOffset=2, BreakBy={Category} SortBy={Subcategory}>([Unit Cost])
The starting point for the count is defined as three rows before the current row (OLAPWinStType=3, OLAPWinStOffset=3). The stopping point for the count is defined as two rows after the current row (OLAPWinEndType=4, OLAPWinEndOffset=2).
This metric is displayed on a report along with Category, Subcategory, and Unit Cost, as shown below.
There are a few facts about this data to take note of.
The first value of OLAPCount Unit Cost is three. This is calculated by counting the current row and two rows after the current row. Even though the calculation starts three rows before the current row, there is no data above the current row to include in the calculation.
The fourth entry for OLAPCount Unit Cost is the first entry that can count all three rows above the current row to two rows below the current row in the calculation. This entry is able to reach the maximum value of six. Notice that after this entry the count begins to decrease because there are no longer two rows below the current row to include in the calculation.
The calculation restarts for the first Subcategory of the next Category because the function is defined to break by the Category attribute.
