Skip to main content

Description

 

Computes the average of numbers within a window moving along a Dimension List. For each Item from a given Dimension List, the average is computed from all defined numbers within the considered window. Blank values are ignored.

The window size can be either:

  • fixed - the syntax defines how many Items are in the window
  • dynamic - the syntax contains an expression that defines window size for each Item

By default, if the input Block is defined over a Time Dimension, the moving average is applied over this Dimension.

 

Syntax

MOVINGAVERAGE(Input, Window Size z, End Offset] t, Dimension])
  • Input - is the data source on which the moving average is computed. It can be a Metric or List with a data type of Integer or Number. 
  • Window Size - is the size of the moving window (number of items considered). It can be an integer above or equal to 1, or an expression comprising a Metric or Metric with calculations. Metrics used for this must have a data type of Integer and comprise Dimensions used by the Input.
  • End Offset - is the offset of an item within the window relative to current one. This also can be an integer or a Metric. Metrics used for this must have a data type of Integer and comprise Dimensions used by the Input.
    It defaults to zero, meaning the window includes all Items from Window Size - 1 to the current Item.
    This setting can be used to either look into past or future values. For example, if you wish to see the moving formula for 12 items into the future on a span of three items, your formula should include this parameter: MOVINGAVERAGE(metric, 3, 12)
  • Dimension - is the Dimension List along which the window is moving. This argument defaults to the Time Dimension of Input if there is exactly one, and must be explicitly specified otherwise.

TIP

If you do not need a variable window size, use an integer. It simplifies the computation and speeds up performance.

 

Return type

Number 

 

Example

Metric SalesByEmployeeAndMonth defined on two Dimensions (Month and Employee):

  Jan Feb Mar Apr May
Alice 1 3   2 8
Bob 2 5 2 1  

 

Window size Metric WindowEmployeeAndMonth:

  Jan Feb Mar Apr May
Alice 2 2   1  
Bob 2     2  

 

Output with window size of 2:

MOVINGAVERAGE(SalesByEmployeeAndMonth, 2)

  Jan Feb Mar Apr May
Alice 1 2 3 2 5
Bob 2 3.5 3.5 1.5 1

 

Output with window size of 3, offset of 1:

MOVINGAVERAGE(SalesByEmployeeAndMonth, 3, 1):

  Jan Feb Mar Apr May
Alice 2 2 2.5 5 5
Bob 3.5 3 2.67 1.5 1

 

Output with window size of 2, Dimension of Employee:

 MOVINGAVERAGE(SalesByEmployeeAndMonth, 2, 0, Employee)

  Jan Feb Mar Apr May
Alice 1 3   2 8
Bob 1.5 4 2 1.5 8

 

Output with dynamic window size provided by Metric WindowEmployeeAndMonth:

MOVINGAVERAGE(SalesByEmployeeAndMonth,WindowEmployeeAndMonth)

  Jan Feb Mar Apr May
Alice 1 2   2  
Bob 2     1.5  

 

Output with dynamic window size, Dimension of Employee:

MOVINGAVERAGE(SalesByEmployeeAndMonth,WindowEmployeeAndMonth,Employee)

  Jan Feb Mar Apr May
Alice 1 3   2  
Bob 1.5     1.5  

 

Note on Blank values: Blank (empty) values are not considered as 0 values. In Pigment the average of a blank and 2 is 2 but the average of 0 and 2 is 1.

 

See also

 

 

 

Why does Bob-Mar in this example MOVINGAVERAGE(SalesByEmployeeAndMonth, 3, 1) = 3?

 

Shouldn’t the moving average equate to 8/3?


Why does Bob-Mar in this example MOVINGAVERAGE(SalesByEmployeeAndMonth, 3, 1) = 3?

 

Shouldn’t the moving average equate to 8/3?

Hi MKohli, good catch! You’re right indeed, the sample didn’t match actual results and was just updated. Thanks a lot for reporting it!