Forum Discussion
ripstaur
Helper III
6 years ago5-Day Moving Average
I have a dataset from GitHub containing cumulative daily Covid19 Deaths and Confirmed cases. It took me a while, but I finally found a solution to one problem, which was calculating a daily differenc...
daxer-almighty
Solution Sage
6 years agoAnd I don't like Fowmy's solution as it breaks down when we are too close to the left edge of the calendar (Dates).
amitchandak
Super User
6 years agodaxer-almighty , How about taking a sum and divide by days in Fowmy solution.
As mesures
Rolling 5 = Divide(CALCULATE(Sum('Table'[Daily Cases]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-5,Day)) ,CALCULATE(distinctcount('Table'[Date]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-5,Day)))
or
Rolling 5 = CALCULATE(Divide(Sum('Table'[Daily Cases]),distinctcount('Table'[Date])),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-5,Day))
With a date table.
- daxer-almighty6 years ago
Solution Sage
amitchandak
You can't calculate 5D average if you don't have 5 days (too close to the left edge of the calendar), so you're targeting a completely different area that has nothing to do with the problem I'm talking about.- amitchandak6 years ago
Super User
daxer-almighty , that is the same idea to count date from the table in the denominator. So if there are not fine days, it divides that many number of days
- Anonymous6 years agoNot applicableamitchandak
"So if there are not fine days, it divides that many number of days"
Such a calculation is NOT 5D average. You're distorting the data this way.