Forum Discussion
Rolling 6 Month Average for data which has missing dates
afaro - My immediate assumption would be that it's something to do with your relationships or the fields that you have in the chart.
It's not clear why you have created the Month Year bridge to connect the fact to the calendar when you have dates in both - my first suggestion would be to remove the bridge and join on dates.
I would also check that you are using the date from the calendar in your visual - rather than the date from sales.
I know you said you don't want to use these, but I have always calculated a moving AVG by using the below - it's very efficient and optimal.
VAR NumOfMonths = 6
VAR LastCurrentDate =
MAX ( 'Date_Table'[Date] )
VAR Period =
DATESINPERIOD ( 'Calendar'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
CALCULATE (
AVERAGEX ( VALUES ( 'Calendar'[Month Year] ), [Revenue] ),
Period
)
VAR FirstDateInPeriod =
MINX ( Period, 'Calendar'[Date] )
VAR LastDateWithSales =
MAX ( 'Sales'[Date] )
RETURN
IF ( FirstDateInPeriod <= LastDateWithSales, Result )
I hope this helps, if testing this works, please accept it as the solution.
- afaro2 years ago
Helper III
Because even though my Sales table has dates, it doesn't have every single date. In a given month there are not more than 10 dates for that month. Hence, the last date of that month is usually not there. That is why I created a year-month bridge table.