Calculating moving averages
The moving average, also known as the rolling average, is a statistical technique often used in events with unpredictable short-term fluctuations in order to smooth their curve and to visualize the pattern of behavior.
The key to get the moving average is to know how to construct a set of members up to and including a specified member, and to get the average value over the number of members in the set.
In this recipe, we are going to look at two different ways to calculate moving averages in MDX.
Getting ready
Start SQL Server Management Studio and connect to your SSAS 2016 instance. Click on the New Query button and check that the target database is Adventure Works DW 2016.
In this example, we are going to use the Date
hierarchy of the Date
dimension. Here is the query we will start from:
SELECT { [Measures].[Internet Order Count] } ON 0, { [Date].[Date].[Date].MEMBERS} ON 1 FROM [Adventure Works]
Execute it. The result shows...