Forum Discussion
Three Month Moving Average Column
Hi there,
I am struggling with creating a column which calculates a 3 month moving average similar to the example below. The 3 month moving average would be the same number for 3 months and based upon the 3 months prior.
| Date | Units | 3 Month Moving Average |
| 1/1/2020 | 25 | |
| 2/1/2020 | 30 | |
| 3/1/2020 | 15 | |
| 4/1/2020 | 50 | 23.33333333 |
| 5/1/2020 | 60 | 23.33333333 |
| 6/1/2020 | 88 | 23.33333333 |
| 7/1/2020 | 66 | 66 |
| 8/1/2020 | 50 | 66 |
| 9/1/2020 | 20 | 66 |
| 10/1/2020 | 45 | 45.33333333 |
| 11/1/2020 | 65 | 45.33333333 |
| 12/1/2020 | 70 | 45.33333333 |
Any help with this would be greatly appreciated!
Hi MikePowerBI ,
Please create a QTR column then create a measure like below:
Measure = VAR CURRENT_QTR =SELECTEDVALUE('Table'[QTR]) var sum_ = SUM('Table'[Units]) return CALCULATE(AVERAGE('Table'[Units]),FILTER(ALL('Table'),'Table'[QTR]=CURRENT_QTR-1))Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 Replies
- V-lianl-msftCommunity Support
Hi MikePowerBI ,
Please create a QTR column then create a measure like below:
Measure = VAR CURRENT_QTR =SELECTEDVALUE('Table'[QTR]) var sum_ = SUM('Table'[Units]) return CALCULATE(AVERAGE('Table'[Units]),FILTER(ALL('Table'),'Table'[QTR]=CURRENT_QTR-1))Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- MikePowerBIHelper II
Hi V-lianl-msft this worked for me, thank you!
- serpiva64Solution Sage
Hi,
Try this one
3 Month Running Total =Var SelectedMaxDate = MAX ( Dates[Date] )Var MinDate =CALCULATE (MIN ( Dates[Date] ),FILTER (ALL ( Dates ),DATEADD (Dates[Date],3,month) >= SelectedMaxDate))ReturnCALCULATE (SUM ( 'Table'[Start of Year Headcount] ),ALL ( Dates ),Dates[Date] <= SelectedMaxDate,Dates[Date] >= MinDate)If this post is useful to help you to solve your issue consider giving the post a thumbs up
and accepting it as a solution !
- MikePowerBIHelper II
Hi serpiva64, thank you for the prompt reply!
Within the formula, could you explain what the [Start of Year Headcount] refers to please?
I used the Units column in the example above and this formula output a single number into the entire column.
- serpiva64Solution Sage
sorry,
i misunderstood your question.
This is the formula of with your data
3 Month Average Running Total =Var SelectedMaxDate = MAX ( Dates[Date] )Var MinDate =CALCULATE (MIN ( Dates[Date] ),FILTER (ALL ( Dates ),DATEADD (Dates[Date],3,MONTH) >= SelectedMaxDate))ReturnCALCULATE (SUM ( 'Table (2)'[Units] ),ALL ( Dates ),Dates[Date] <= SelectedMaxDate,Dates[Date] >= MinDate)/3and produces this:but unfortunatly it is not what you want.