Forum Discussion
Moving average (bespoke periods)
- 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 🙂
Thanks so much for this 🙂
i have followed the logic to add periodic dates which have aligned my data. I have also split the targets down to day level granularity - using a duration column to divde the period number.
I have another challenge which i think is an easy one but is confusing me, will post in a new thread.
Thanks again
Dan