Forum Discussion

dantheram's avatar
dantheram
Icon for Helper II rankHelper II
4 years ago
Solved

Moving average (bespoke periods)

Hi All   first post 🙂   I have the below table which i need to add a periodic average to, so i can show a rolling 13 period annual average; period 13 of 2018/19 would be the average of periods 1...
  • TheoC's avatar
    TheoC
    4 years ago

    dantheram thanks for the additional information!  Makes complete sense.

     

    A couple of things, one way to achieve what you want to get the dates aligned to the respective periods you want is using the below and adapting it to your table name and to your period start date:

     

    NewPeriod =

    VAR _NewPeriod = 'Table'[Date]
    VAR _Year = YEAR ( 'Table'[Date] )
    VAR _P01Start = DATE ( _Year , M , D )
    VAR _P02Start = DATE ( _Year , M , D )
    VAR _P03Start = DATE ( _Year , M , D )
    VAR _P04Start = DATE ( _Year , M , D )
    VAR _P05Start = DATE ( _Year , M , D )
    VAR _P06Start = DATE ( _Year , M , D )
    VAR _P07Start = DATE ( _Year , M , D )
    VAR _P08Start = DATE ( _Year , M , D )
    VAR _P09Start = DATE ( _Year , M , D )
    VAR _P10Start = DATE ( _Year , M , D )
    VAR _P11Start = DATE ( _Year , M , D )
    VAR _P12Start = DATE ( _Year , M , D )

    RETURN

        SWITCH ( TRUE ( ) ,
            _NewPeriod < _P02Start , "P01" ,
            _NewPeriod < _P03Start , "P02" ,
            _NewPeriod < _P04Start , "P03" ,
            _NewPeriod < _P05Start , "P04" ,
            _NewPeriod < _P06Start , "P05" ,
            _NewPeriod < _P07Start , "P06" ,
            _NewPeriod < _P08Start , "P07" ,
            _NewPeriod < _P09Start , "P08" ,
            _NewPeriod < _P10Start , "P09" ,
            _NewPeriod < _P11Start , "P10" ,
            _NewPeriod < _P12Start , "P11" ,
            _NewPeriod < _P13Start , "P12" ,
            "P13" )

     

    Change the "M" and "D" in the VARs to a numeric month (i.e. 1 will be Jan) and D to the day of the respective month (i.e 1 to 31).

     

    Add this as a Calculated Column and you will be able to use the PXX to get your output. Below is a solution I put together for a separate post and it was to do with unusual Quarterly Start Dates 🙂