Forum Discussion
Calculate monthly moving average including blank values
- 5 years ago
Hi marius_04
I was working up a moving average yesterday based on below vid. Begin at the 5:50 mark, since I'm not going to be able to say it better.
https://www.youtube.com/watch?v=3VajEecHMSs
---Updated---Well, my newly created moving margin was suffering from the same issue as yours. Thanks for helping me notice that! 😉
You could add 6 months to the minimum selected date in your date range, then check if the current context date is >= to your "new" minimum date.
For instance, making two changes to the code from the vid shared above worked for me... // Created this variable which adds 14 days to the minimum selected date VAR __MinDateSelected = CALCULATE( MIN('Dates'[Date]) + 14, ALLSELECTED('Dates'[Date]) ) ... RETURN // Once the current context date is >= to my new minimum date, then move on in the process IF( MAX(Dates[Date]) >= __MinDateSelected, IF( MAX(Dates[Date]) <= __LastSalesDate, __Result ) )
Now my moving average line begins 14 days into the chart.Hope this helps with your first 6 months issue.
James
Hi marius_04
I was working up a moving average yesterday based on below vid. Begin at the 5:50 mark, since I'm not going to be able to say it better.
https://www.youtube.com/watch?v=3VajEecHMSs
---Updated---
Well, my newly created moving margin was suffering from the same issue as yours. Thanks for helping me notice that! 😉
You could add 6 months to the minimum selected date in your date range, then check if the current context date is >= to your "new" minimum date.
For instance, making two changes to the code from the vid shared above worked for me
...
// Created this variable which adds 14 days to the minimum selected date
VAR __MinDateSelected = CALCULATE( MIN('Dates'[Date]) + 14, ALLSELECTED('Dates'[Date]) )
...
RETURN
// Once the current context date is >= to my new minimum date, then move on in the process
IF( MAX(Dates[Date]) >= __MinDateSelected,
IF(
MAX(Dates[Date]) <= __LastSalesDate,
__Result
)
)
Now my moving average line begins 14 days into the chart.
Hope this helps with your first 6 months issue.
James
dudeyates thanks a lot four your proposal. The video was great and I was able to fix the problem.
At the end, I used the following:
IF( ENDOFMONTH(Calender[Date].[Date]) < DATE(2018,06,01), BLANK(),​
And, maybe you faced the same problem, at the end of the graph, the average goes beyond today's date (6 months in my case). With the following expression, you limit the average to the current date:
IF(ENDOFMONTH('Calender'[Date].[Date])>TODAY(), BLANK(),
Thanks for your support and Best