MicroStrategy ONE

OLAPMax (OLAP Maximum)

Returns the maximum value based on comparing the current value, preceding values, and succeeding values as defined in the function arguments. Unlike RunningMax and MovingMax, which can only include values above the current row in the calculation, you can use OLAPMax 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

OLAPMax<OLAPWinStType, OLAPWinStOffset, OLAPWinEndType, OLAPWinEndOffset, BreakBy, SortBy>(Argument)

Where:

  • BreakBy is the attribute indicating where the calculation restarts.
  • SortBy is the attribute or metric by which the data is sorted.
  • OLAPWinStType defines 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 corresponding OLAPWinStType value in parentheses:
    • Top of data set (0): The calculation starts at the top value as determined by the BreakBy and SortBy values.
    • Current row (2): The calculation starts at the current row.
    • N rows before current row (3): The calculation starts a number of rows before the current row. You define this offset of rows with the OLAPWinStOffset parameter described below.
    • N rows after current row (4): The calculation starts a number of rows after the current row. You define this offset of rows with the OLAPWinStOffset parameter described below.
  • OLAPWinStOffset defines the offset of rows from the current row to start the calculation. You can define this offset if the OLAPWinStType parameter is defined as N rows before current row (3) or N rows after current row (4).
  • OLAPWinEndType defines 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 corresponding OLAPWinEndType value in parentheses:
    • Bottom of data set (1): The calculation stops at the bottom value. The top value is determined by the BreakBy and SortBy values.
    • Current row (2): The calculation stops at the current row.
    • N rows before current row (3): The calculation starts a number of rows before the current row. You define this offset of rows with the OLAPWinEndOffset parameter described below.
    • N rows after current row (4): The calculation starts a number of rows after the current row. You define this offset of rows with the OLAPWinEndOffset parameter described below.
  • OLAPWinEndOffset defines the offset of rows from the current row to stop the calculation. You can define this offset if the OLAPWinEndType parameter is defined as N rows before current row (3) or N rows after current row (4).
  • Argument is 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 OLAPMax Unit Cost metric is created using the OLAPMax function based on the Unit Cost metric, as defined below:

OLAPMax<OLAPWinStType=3, OLAPWinStOffset=3, OLAPWinEndType=4, OLAPWinEndOffset=2, BreakBy={Category} SortBy={Subcategory}>([Unit Cost])

The starting point for the calculation is defined as three rows before the current row (OLAPWinStType=3, OLAPWinStOffset=3). The stopping point for the calculation 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 OLAPMax Unit Cost is $14. This is calculated by returning the maximum value of $14, $11, and $6. These are included because the calculation ends 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 second value also returns $14 as it returns the maximum value of $14, $11, $6, and $7.

The third value for OLAPMax Unit Cost is the first entry that includes $26 in its maximum calculation. The rest of the OLAPMax Unit Cost values for the Books Category return $26 because this is the maximum value, and it is within the window of three rows above the current row to two rows below the current row.

The calculation restarts for the first Subcategory of the next Category because the function is defined to break by the Category attribute.