Forum Discussion
Better Rolling Average Formula
- 5 years ago
Your formula is great, but you have hard coded 42 days. But you don't have 42 days when the time period is in the first 41 days of data. Write a test measure that counts the days, eg countrows(DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -42, DAY ))
and add it to the visual. I hope it will tell you how many days you are tracking. Then divide by this instead of 42.
- 5 years ago
Another approach would be to use AVERAGEX, which should keep the numerator and denominator in sync.
Revs R42DA = AVERAGEX ( DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -42, DAY ), [Revenue] )This is simpler but less computationally efficient than methods that don't require calculating Revenue for each day in the period separately.
Another approach would be to use AVERAGEX, which should keep the numerator and denominator in sync.
Revs R42DA =
AVERAGEX (
DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -42, DAY ),
[Revenue]
)
This is simpler but less computationally efficient than methods that don't require calculating Revenue for each day in the period separately.