MOVINGAVERAGE

Updated on

MOVINGAVERAGE is a DAX function that calculates a moving average along a specified axis in a visual calculation data grid.

Syntax

MOVINGAVERAGE(
   Expression,
   WindowSize,
   IncludeCurrent,
   Axis,
   Blanks,
   Reset
)
Argument Properties Description
Expression The expression to be evaluated for each row.
WindowSize The length of the moving window, that is, how many rows will be included. This value should be greater than or equal to 1.
IncludeCurrent Optional A logical value specifying whether or not to include the current row. If FALSE, the window will contain the last WindowSize values before the current row. Default value is TRUE.
Axis Optional An axis reference.
Blanks Optional An enumeration that defines how BLANK values are ordered. Valid values are: DEFAULT, LAST, FIRST.
Reset Optional Specifies how the calculation restarts. Valid values are: None, LowestParent, HighestParent, or an integer.

Return Values

A scalar value, the moving average at the current element of the axis.

Remarks

This function can be used in visual calculations only.

The includeCurrent, axis, blanks and reset parameters can be omitted.

Example 1

Given a table that summarizes the total sales for each product category and calendar month, the following DAX query adds a column with the average of total sales for that category in the last 6 months:

AvgSalesLast6Months = MOVINGAVERAGE([SalesAmount], 6, Rows)

The screenshot below shows the visual matrix and the visual calculation expression:

DAX visual calculation

Example 2

Given the same table, the following DAX query adds a column with the average of total sales for that category in the previous 12 months (not including the current month):

AvgSalesPrev12Months = MOVINGAVERAGE([SalesAmount], 12, FALSE, Rows, KEEP)

Other functions related to MOVINGAVERAGE are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/movingaverage-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy