Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi,
I am trying to show my data as a rolling average for the past 3 months. I have a measure called '% Aware' which calculates the % of a column called 'Awareness'. DAX code below (Sheet1 and Sheet2 are linked by UNIQUEID 1 to 1 relationship).
What I now need is this same line graph but showing a rolling average of the past 3 months for each month. I've tried various methods but haven't found any which work with a measure. The problem is that as soon as I add month into the x-axis the rolling average gets filtered by each month (and therefore isn't including the data for the previous 2). I need the % for "Jul-22" to be the average % of the past 3 months. This DAX code seems to work but as soon as I add month to the x-axis it reverts to showing the % aware for each month, not the rolling average.
I can calculate the rolling average by creating a measure for each month but then I can't plot these into the y-axis of a line chart. Also the months go back to 2017 so it would mean creating a huge number of measures
Solved! Go to Solution.
Please refer to this page for details about how to calculate rolling averages.
To whet your appetite...
Please refer to this page for details about how to calculate rolling averages.
To whet your appetite...
Thank you! I got that to work using the method in the link.
I just have one further thing I need some help with which is that for the first two months I need the values to be blank - in the below image it would be Oct 2021 and Nov 2021 which should be blank as they aren't showing the past 3 month rolling average (Nov 2021 is an average of Oct-21 and Nov-21 data, Oct 2021 is just the average for Oct-21).
There is a date slicer on the page for the user to select the date range to show in the chart. I just need the chart to show nothing for whatever the first two months are which are selected in the slicer - so the line would start from the 3rd month onwards.
This is the DAX measure for total awareness. I'm not too sure where to start with adding in something to omit the first two months or if it would be easier to make a separate measure perhaps?
Any help much appreciated!
// First of all, you should number your months
// throughout all years starting with 1 and
// moving by one till the very last month in
// the calendar. Do not use Year Month Number
// which I believe resets every year and even
// if not, I guess it's not consecutive. You
// have to have a field that numbers all your
// months consecutively and does not reset
// when a new year starts. Let's say such a field
// is called MonthID (because this is what it
// really stands for).
// You have to put fields from the Date table
// onto the x-axis for this to work. You should
// never ever use fields from fact tables in
// any of your visuals. This is only allowed
// if you troubleshoot. Users should never be
// able to slice data via fact table's fields.
// Best Practice? All such fields should be
// hidden. Even more, the fact tables should
// always be hidden. For measures, a separate
// table should be created without any fields
// and measures should be stored on this very
// table.
// Then you'll write:
Total Awareness =
VAR MonthsInRange = 3
// Get the last visible month's ID.
VAR LastMonthRange = MAX( 'Date'[MonthID] )
// The first month for the calculation will
// be the one with MonthID removed (MonthslnRange - 1)
// times since you need MonthsInRange months in the range.
VAR FirstMonthRange = LastMonthRange - (MonthsInRange - 1)
VAR ThePeriod = // don't hard-code numbers in the names
FILTER(
ALL( 'Date'[MonthID] ),
FirstMonthRange <= 'Date'[MonthID]
&&
'Date'[MonthID] <= LastMonthRange
)
VAR Result =
IF(
// This effectively makes sure that
// you've got 3 full months available.
COUNTROWS( ThePeriod ) = MonthsInRange,
CALCULATE(
AVERAGEX(
ThePeriod,
// Make sure this measure is correct!
[% Aware]
),
REMOVEFILTERS( 'Date' )
)
)
RETURN
Result
I'm not sure how to add a Month ID column to the Date table. The Date table is a calculated table so I can't add a conditional column in power query editor which is what I would normally do. I copied the DAX code below from the link you sent.