I have two tables: FactTable and Calendar. My Fact table has consumption data for a variety of objects, and I want to create a 14 day rolling average measure. I have been somewhat successful, but I've noticed that whenever the consumption quantity for an object is zero, the rolling average displays zero for that day. The values that are not zero are correct, but I would like to have a continuous rolling average rather than having gaps.
Here is my Code:
=VAR Interval = -14
VAR FilteredDate = LASTDATE(FactTable[Date])
VAR DateRange = DATESINPERIOD(
'Calendar'[DateKey], FilteredDate, Interval, DAY)
VAR ConsumptionTotal = CALCULATE(
SUM( FactTable[Consumption Qty] ),
DateRange )
VAR DaysTotal = CALCULATE(
DISTINCTCOUNT('Calendar'[DateKey]),
DateRange)
RETURN
ConsumptionTotal / DaysTotal
What I think is happening is that the filtering from the pivot table for the object (1804 in the example above) is stopping the DateRange variable from properly filtering the FactTable into the dates within the range I want because when there is zero consumption quantity it does not return a full date range to SUM() with.
I've tried everything I can think of but whenever I test out ALL(), ALLSELECTED(), etc. to try to stop the filtering of the DateRange I get errors. I'm very new to DAX so I'm sure there something simple I'm missing. The scope of filters is very confusing to me.