Forum Discussion

marius_04's avatar
marius_04
New Member
5 years ago
Solved

Calculate monthly moving average including blank values

Hi all,    I want to create a rolling average with a window of 6 months.   The following measure: 6-month average Sales Impact = IF(ENDOFMONTH('Calender'[Date].[Date])>TODAY(), BLANK(), ( I...
  • dudeyates's avatar
    dudeyates
    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