The MOVINGSUM function returns the sum of values over a changing time range. As the time range moves through the data, it aggregates the values for the updated time range.

Use this function to create rolling summaries or forecasts based on a series of data, such as weekly sales or performance results.

MOVINGSUM(Line item to aggregate [, Start offset] [, End offset] [, Aggregation method])

ArgumentData typeDescription
Line item to aggregate (required)Number, boolean, date, list, or text

The line item containing the values that you want to aggregate over a period of time. 

This argument must be a line item.

Start offset 
Number

The starting value for the aggregation.

When you omit Start offset, the aggregation is performed over the entire time range.

End offset 
NumberThe ending value for the aggregation.
Aggregation methodKeyword

The aggregation method to use.

The available keywords are SUM, AVERAGE, MIN, MAX, ANY, ALL, FIRSTNONBLANK, LASTNONBLANK, and TEXTLIST.

There's more information in the Aggregation method section below.

The MOVINGSUM function returns a value that matches the data type of the Line item to aggregate.

KeywordData typePurpose
SUMNumberAdds the input values
AVERAGENumberCalculates the average of the input values
MINNumber, dateIdentifies the minimum input value
MAXNumber, dateIdentifies the maximum input value
ANYBooleanChecks and returns TRUE if any input value is TRUE
ALLBooleanChecks and returns TRUE if all input values are TRUE
FIRSTNONBLANKDate, list, textReturns the first non-blank input value
LASTNONBLANKDate, list, textReturns the last non-blank input value
TEXTLISTTextConcatenates the input values with a " , " separator to create a single text value

When you omit the Aggregation method, the default behavior depends on the data type of the Line item to aggregate:

  • If the data type of the Line item to aggregate is a number, the default method is SUM.
  • If the data type of the Line item to aggregate is boolean, the default method is ANY.
  • If the data type of the Line item to aggregate is a date, list, or text, the default method is FIRSTNONBLANK.
BehaviorPolarisClassic
Two-argument variantMOVINGSUM(source, start) aggregates the source values from the point corresponding to the Start offset to the end of the time dimension.MOVINGSUM returns the value of the source at the point corresponding to the Start offset.
Blank values in End offsetAggregates the source values from the point corresponding to the Start offset to the end of the time range, for example, 12 if the source is dimensioned by months.End offset defaults to the value as the Start offset, for example, MOVINSUM(source, 4) is considered as MOVINGSUM(source, 4, 4).
Reference across time rangesCan reference different time ranges. For example, MOVINGSUM can reference a Line item to aggregate with a time dimension based on a different time range than the time dimension of the target line item.Can't reference different time ranges.
Reference across timescalesCan't refer to a source line item with a time dimension at a coarser timescale than the time dimension of the target.Always possible to refer to a source line item with a coarser time dimension.
NaN handling in argumentsWhen either the Start offset or End offset argument is NaN, MOVINGSUM returns the default value for the type of Line item to aggregate.NaN in either argument is treated as the offset corresponding to the earliest period in the time dimension.
Empty aggregation behaviorWhen there are no values to aggregate, that is when the Start offset is greater than the End offset, MOVINGSUM returns the default value for the type of Line item to aggregate.
The default values include 0 for numbers, False for Boolean, and blank for other data types.
Returns value depending on the combination of the aggregation method used and its data type.
Blank handling in MIN aggregation method on datesWhen comparing blank with a non-blank date value, MIN ignores blank and returns the non-blank value. When all values are blank, it returns blank.When blank is compared with a non-blank date value, it returns blank.
Unavailable aggregation methodsFIRSTNONBLANK, LASTNONBLANK, and TEXTLIST aren't available.All aggregation methods are available.

 MOVINGSUM(Bonus, -2, 0)


Jan 22Feb 22Mar 22Apr 22May 22Jun 22Jul 22Aug 22
Bonus6,1505,8505,9006,0254,8504,9505,6006,250
MOVINGSUM(Bonus, -2, 0)6,15012,00017,90017,77516,77515,82515,40016,800

In MOVINGSUM(source, -1, 0), for example, if the Start offset (-1) or End offset (0) leads to values outside the time range of the Line item to aggregate, values outside the range are ignored in the aggregation.

If you use a decimal number for the Start offset or End offset, MOVINGSUM rounds it to the nearest value.


Jan 23Feb 23Mar 23Apr 23May 23Jun 23Jul 23Aug 23Sep 23
Number200250300500400450200400350
MOVINGSUM(Number, -2, 0, AVERAGE)200225250350400450350350316.7
MOVINGSUM(Number, 1, 3, MAX)5005005004504504004003500
MOVINGSUM(Number, -4, 2, SUM)7501,2501,6502,1002,3002,5002,6002,3001,800
Boolean
MOVINGSUM(Boolean, -1, 0, ANY)
IF MOVINGSUM(Boolean, -1, 0, ALL) THEN 1 ELSE 0001100110
Date02/01/202306/02/202316/03/202320/04/202319/05/202323/06/202321/07/202330/08/202314/09/2023
MOVINGSUM(Date, -1, 0, MAX)06/02/202316/03/202320/04/202319/05/202323/06/202321/07/202330/08/202314/09/202314/09/2023