Forum Discussion
How to create a moving average for a merged table in Power Query
- 4 years ago
Hi,
I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.
- I created a sample pbix file like below.
- it is for creating a measure to provide 28days rolling average (daily avg.)
- I created a calendar table to use time-intelligent DAX function -> DATESINPERIOD & LASTDATE
Rolling four weeks avg conversion: = VAR rollingfourweeks = DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -28, DAY ) VAR _condition = COUNTROWS ( rollingfourweeks ) >= 28 RETURN AVERAGEX ( rollingfourweeks, [Conversion measure:] ) * DIVIDE ( _condition, _condition )
Hey, i have one more i need help with.
In this case, the rolling 4 week averagewould be a sum of the Actuals col grouped on the week and state cols, and then divided by 4. Any ideas?
Hi,
Thank you for your message, and please check the below picture and the attached pbix file.
I tried to create a new sample pbix file like below.
I am not sure how your data model looks like, and if the below is not what you are looking for, please share your sample pbix file's link here. And then I can try to look into it to have a more accurate solution.
Rolling avg 4 wks: =
VAR _fourweekstable =
DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -28, DAY )
VAR _newtable =
FILTER (
ADDCOLUMNS (
SUMMARIZE (
CALCULATETABLE ( 'Calendar', 'Calendar'[Date] IN _fourweekstable ),
'Calendar'[Start of Week]
),
"@actuals", [Actuals sum:]
),
[@actuals] <> BLANK ()
)
VAR _condition =
COUNTROWS ( _newtable ) >= 4
RETURN
AVERAGEX ( _newtable, [@actuals] ) * DIVIDE ( _condition, _condition )