Forum Discussion
ElliotP
10 years agoPost Prodigy
Moving Average
Hi, I've just started using PowerBI and I'm a massive fan of the tool. I've been trying to calculate a simple moving average for Months vs Sessions. I've tried quite a lot of things, googling...
- 10 years ago
Firstly you need a column of date with full date format. Then you can use calculated measure to get the expected result. Please refer to following steps.
- Create a calculated column for the date.
FullDate = DATE ( 2016, 'Session'[Month of the Year], 1 )
- Create a measure for 3 months moving average. You can change the number of months if you want.
Moving_Average_3_Months = CALCULATE ( AVERAGEX ( 'Session', 'Session'[Sessions] ), DATESINPERIOD ( 'Session'[FullDate], LASTDATE ( 'Session'[FullDate] ), -3, MONTH ) ) - Drag the Line Chart into your canvas as below.
- Create a calculated column for the date.
v-sihou-msft
10 years agoMicrosoft Employee
Firstly you need a column of date with full date format. Then you can use calculated measure to get the expected result. Please refer to following steps.
- Create a calculated column for the date.
FullDate = DATE ( 2016, 'Session'[Month of the Year], 1 )
- Create a measure for 3 months moving average. You can change the number of months if you want.
Moving_Average_3_Months = CALCULATE ( AVERAGEX ( 'Session', 'Session'[Sessions] ), DATESINPERIOD ( 'Session'[FullDate], LASTDATE ( 'Session'[FullDate] ), -3, MONTH ) ) - Drag the Line Chart into your canvas as below.
ElliotP
10 years agoPost Prodigy
Thank you so much for the responses.
v-sihou-msft Thank you so much.
sdjensen I took your advice and looked into creating its own date table, extremely useful!
I used this code to create a 10 day Simple Moving average:
Moving_Average_3_Months =
CALCULATE (
AVERAGEX ( 'All Web Site Data', 'All Web Site Data'[Sessions] ),
DATESINPERIOD (
'Table123'[DateKey],
LASTDATE ( 'Table123'[DateKey] ),
-10,
DAY
)
)Link: https://gyazo.com/bb02f6541c6f0e99c4477f6b4ead42cd
The drill down feature doesn't seem to want to work for me. Should I simple create my own hierarchy for this?