Forum Discussion
IF plus Rolling Average?
- Anonymous8 years ago
pan,
What DAX formula do you use to calculate rolling average? I make a test using the following DAX to calculate rolling average, the rolling average measure returns value even some products have no data for 2015. And when you create visuals using different legend level(Product or County) with this measure, the measure returns expected values.{Base value} rolling average = IF( ISFILTERED({Date}), ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy."), VAR __LAST_DATE = LASTDATE({Date}.[Date]) RETURN AVERAGEX( DATESBETWEEN( {Date}.[Date], DATEADD(__LAST_DATE, {Periods Before}, {Period}), DATEADD(__LAST_DATE, {Periods After}, {Period}), ), CALCULATE({Base value}) ) )
Reference:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Rolling-Average/m-p/160720
Regards,
Lydia
pan,
What DAX formula do you use to calculate rolling average? I make a test using the following DAX to calculate rolling average, the rolling average measure returns value even some products have no data for 2015. And when you create visuals using different legend level(Product or County) with this measure, the measure returns expected values.
{Base value} rolling average =
IF(
ISFILTERED({Date}),
ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy."),
VAR __LAST_DATE =
LASTDATE({Date}.[Date])
RETURN
AVERAGEX(
DATESBETWEEN(
{Date}.[Date],
DATEADD(__LAST_DATE, {Periods Before}, {Period}),
DATEADD(__LAST_DATE, {Periods After}, {Period}),
),
CALCULATE({Base value})
)
)
Reference:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Rolling-Average/m-p/160720
Regards,
Lydia