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
Hi brekeke,
Did you try the method of Greg_Deckler? You measure could be like this:
New Measure =
CALCULATE (
SUMX (
SUMMARIZE ( 'Sales', 'Product'[Color], "Amount", [Your old measure] ),
[Amount]
),
DATESINPERIOD ( 'Calender'[Date], MAX ( 'Calender'[Date] ), -3, MONTH )
)It would be great if you can share your pbix file. Dummy one is enough.
Best Regards,
Dale
Thanks v-jiascu-msft,
I quickly tried the below formula but it doesn't work. My assumption is that my data structure is making me fool.
What I did not mention previously is that the period column is dynamically calculated: it can be changed with a slicer, thus it can show quarterly and weekly data as well.
IMO, your formula doesn't work because it wrongly summarizing:
1. measure is the original calculated measure
2. measure is exactly your formula
Values are different, so filtering for time interval works, but somehow it's grouping badly (according to my humble opinion)...
Thanks
