Search code examples
powerbidaxrolling-average

Calculate Average of last n number of weeks in Power BI


I have data in which a row haa number of week and the corresponding sales on this week. Now for each week i want to calculate the average sales of last 8 weeks using DAX formula.


Solution

  • a solution posted here makes use of DATESINPERIOD() and LASTDATE():

    Moving_Average_3_Months = CALCULATE ( AVERAGEX ( 'Session', 'Session'[Sessions] ), DATESINPERIOD ( 'Session'[FullDate], LASTDATE ( 'Session'[FullDate] ), -3, MONTH ) )

    I hope this helps