MicroStrategy ONE

MovingSum

Returns the moving sum of the current value and preceding values as defined in the function arguments. The calculations can be restarted based on attributes set in the function parameters. This is an OLAP function.

Syntax

MovingSum <BreakBy,SortBy>(Argument, WindowSize)

Where:

  • Argument is a metric representing a list of numbers.
  • BreakBy is the attribute indicating where the calculation restarts.
  • SortBy is the attribute or metric by which the data is sorted.
  • WindowSize is a positive integer indicating the number of values to sum in each calculation.

Expression

Where:

  • yi = metric value at the ith row
  • m = window size
  • n = number of rows/metric values

Example

This simple example illustrates how the MovingSum function moves through a list of values calculating and returning the sum of a specified number of values. In this case the window size is set to 2 meaning that the sum in the MovingSum column represents the current value added to the value from the value list that precedes it. The calculation is shown in the following table.

Values MovingSum

10

10

20

30 (20+10)

30

50 (30+20)

15

45 (15+30)

5

20 (5+15)