Forum Discussion
Rolling Average Issues
Hi hungry_learner - you're facing occurs because of how Power BI's line charts handle measures and filters. When you add a measure to a line chart without explicitly filtering by Country, the measure evaluates for all data points, and this can lead to blank results if no context is provided for the Country column.
Rolling Average =
VAR MaxDate = MAX('3-Year Calender'[Date])
VAR StartDate = EDATE(MaxDate, -36)
RETURN
CALCULATE(
AVERAGEX(
FILTER(
ALL('3-Year Calender'),
'3-Year Calender'[Country] = SELECTEDVALUE('3-Year Calender'[Country]) &&
'3-Year Calender'[Date] <= MaxDate &&
'3-Year Calender'[Date] > StartDate
),
'3-Year Calender'[Value]
)
)
You can adjust the measure to handle scenarios where no country is selected by providing a default behavior:
Rolling Average =
VAR MaxDate = MAX('3-Year Calender'[Date])
VAR StartDate = EDATE(MaxDate, -36)
VAR Result =
CALCULATE(
AVERAGEX(
FILTER(
ALL('3-Year Calender'),
'3-Year Calender'[Country] = SELECTEDVALUE('3-Year Calender'[Country]) &&
'3-Year Calender'[Date] <= MaxDate &&
'3-Year Calender'[Date] > StartDate
),
'3-Year Calender'[Value]
)
)
RETURN
IF(ISBLANK(SELECTEDVALUE('3-Year Calender'[Country])), BLANK(), Result)
Try the above both logics and let us know.