Forum Discussion

GGerritsen's avatar
GGerritsen
Helper I
1 year ago
Solved

Slicer changing 4 week average rolling calculation

I have a report that calculate the rolling average 4 weeks in sales.   4Wk rolling Avg Sales = VAR NumOfDays = 4 * 7 VAR LastDateInPeriod =     MAX ( 'Forecast History'[Start of Week] ) VAR Fi...
  • v-ssriganesh's avatar
    v-ssriganesh
    1 year ago

    Hi GGerritsen,

    Thank you for update. Based on your explanation, it looks like applying the last 12 weeks filter is also limiting the data available for calculations, which is why the first few weeks in your filtered range don't have the correct rolling average values. Since a 4-week rolling average requires past data to compute correctly, filtering out earlier weeks impacts the calculation.

    Instead of applying the last 12 weeks filter to the dataset, we need to adjust the DAX measure so that it still considers all available data but only displays the last 12 weeks.

     

    Try updating your DAX measure like this:

    4Wk Rolling Avg Sales Fixed =
    
    VAR RollingAvg =
    
        AVERAGEX(
    
            DATESINPERIOD(
    
                'Calendar'[Date],
    
                MAX('Calendar'[Date]),
    
                -4,
    
                WEEK
    
            ),
    
            CALCULATE(SUM('Forecast History'[Sales]), ALL('Calendar'[Relative Week]))
    
        )
    
    RETURN
    
        RollingAvg
    • Instead of filtering the dataset directly, apply the "Last 12 Weeks" filter only to the visual in the Filters pane. Set it to show values greater than or equal to -11 and less than or equal to 0.

     

    If you find this information useful, please accept it as a solution and give it a 'Kudos' to assist others in locating it easily.
    Thank you.