Forum Discussion
Moving Average Of Calculated Measure
- 8 years ago
Hi brekeke,
Please try this formula.
Measure 2 = VAR weekPeriods = CALCULATE ( DISTINCTCOUNT ( tbl_periods_all[Period Column] ), DATESINPERIOD ( 'Calendar'[Date], MIN ( tbl_periods_all[Start Of Period] ), -21, DAY ), ALL ( tbl_periods_all[Period Column] ) ) VAR pPeriods = CALCULATE ( DISTINCTCOUNT ( tbl_periods_all[Period Column] ), DATESINPERIOD ( 'Calendar'[Date], MIN ( 'tbl_periods_all'[Start Of Period] ), -7, MONTH ), ALL ( tbl_periods_all[Period Column] ) ) RETURN IF ( MIN ( 'Period Selector'[period] ) = "Week", CALCULATE ( SUM ( data[fact] ), DATESINPERIOD ( 'Calendar'[Date], MIN ( 'tbl_periods_all'[Start Of Period] ), -21, DAY ), ALL ( tbl_periods_all[Period Column] ) ) / weekPeriods, CALCULATE ( SUM ( data[fact] ), DATESINPERIOD ( 'Calendar'[Date], MIN ( 'tbl_periods_all'[Start Of Period] ), -7, MONTH ), ALL ( tbl_periods_all[Period Column] ) ) / pPeriods )Best Regards,
Dale
Thanks for the advice. It might work but first I need to fully understand your solution. I'm fairly new into power BI and the logic is less than obvious to me sometimes...
Hi brekeke,
It would be great if you can provide the DUMMY pbix file (Not your real data). I can add the solution to the file and send back to you. Then it could be easier for you to try the solution out.
Best Regards,
Dale
- brekeke8 years agoFrequent Visitor
Thanks v-jiascu-msft,
I'll try to make a dummy file, but it will take some time I guess.
- brekeke8 years agoFrequent Visitor
Hi v-jiascu-msft,
Here you go: https://www.dropbox.com/s/nd46tlcbz98th1p/moving_average_dummy_v0.1.pbix?dl=0
Data structure is exactly the same except some supporting table but those don't matter.
Thanks,
breki
- v-jiascu-msft8 years agoMicrosoft Employee
Hi brekeke,
I made a few changes in your file. Please check it out here.
The measure is:
Measure = IF ( MIN ( 'Period Selector'[period] ) = "Week", CALCULATE ( SUM ( data[fact] ), DATESINPERIOD ( 'Calendar'[Date], MIN ( 'tbl_periods_all'[Start Of Period] ), -21, DAY ), ALL ( tbl_periods_all[Period Column] ) ), CALCULATE ( SUM ( data[fact] ), DATESINPERIOD ( 'Calendar'[Date], MIN ( 'tbl_periods_all'[Start Of Period] ), -7, MONTH ), ALL ( tbl_periods_all[Period Column] ) ) )Best Regards,
Dale