Skip to main content
|

PowerPivotPro's FAQ Site

Go Search
  
PowerPivotPro's FAQ Site > The Great PowerPivot FAQ > How can I create a moving average calculated measure?  

The Great PowerPivot FAQ: How can I create a moving average calculated measure?

Title

How can I create a moving average calculated measure? 

Answer

If you have a date column in a table that's associated with the values for which you want to create a moving average calculated measure, you can use PowerPivot's time intelligence functions.
 
Let's assume that you have a table called Internet Sales and a field called SalesAmount, for which you want to create a monthly moving average. Your date field is [InvDate] (in a table named Date, linked to SalesData) and you want to calculate the moving average based on monthly data. You have [Year] and [Month] fields (from your Date table) in your PivotTable.
 
For performance and readability reasons, I recommend that you break down the task into a series of calculated measures.
 
First create a measure for averaging the sales by month: [Average Sales] = SUM('InternetSales'[SalesAmount])/COUNTROWS(DISTINCT('Date'[Month]))
 
For ease of modification later, create a measure for the moving average lag period: [Lag]=3 (initially, let's assume that you want a three month moving average).
 
Create a measure for the first month in the moving average: [FirstDate]=STARTOFMONTH(DATEADD('Date'[InvDate],-[Lag],month))
 
Create a measure for the last month in the moving average (the previous month):
[LastDate]=ENDOFMONTH(DATEADD('Date'[InvDate],-1,month)) 
 
Finally, create a measure for the moving average:
=IF([FirstDate]<>"",[Average Sales](DATESBETWEEN('Date'[InvDate],[FirstDate],[LastDate]),ALL('InternetSales')))
 

Client/Server

Client 

Topic

F - Calculations (DAX) 

Purpose

Information 

Answered?

Yes 

Contributor

Colin Banfield 

Título

 

Resposta

 

Frage

Wie kann ich eine "moving average" Kennzahl berechnen? 

Antwort

 

preRTM

 
Attachments
Created at 1/20/2010 11:44 PM  by Colin 
Last modified at 4/23/2010 1:33 PM  by Jochen Juelke