Forum Discussion
measure moving average
- 8 years ago
Hey,
here you will find my pbix file. I just added another page and created a simple table, this way was somewhat easier to read, than deduct the expected result from your graphs (wondering about the size of your screen :-) ).
I created 4 measure, two measures calculate the sum of quantities and sessions for the last 10days. The measure for quantity looks like this (session is similar)
sum quantity last 10 = var mylastdate = LASTDATE(VALUES(Calendar[Date])) var sumQuantity = CALCULATE( SUM('OrderItems'[Quantity]) ,DATESINPERIOD(Calendar[Date], mylastdate,-10,DAY) ) return sumQuantityAnd two measure that calculate the average
- the first one "avg conversion rate simple" dividing by dividing [sum quantity last 10] / [sum sessions last 10]
- the seond one "avgx conversion rate" iterates over the last 10 days and calculates the average from the divisions for each day
Here is the DAX of the first one, I recreated measures as variables to be sure to understand what's happening, I guess you can replace some of the DAX statement by simply using your existing measures:
avg conversion rate simple = var mylastdate = LASTDATE(VALUES(Calendar[Date])) var sumQuantity = CALCULATE( SUM('OrderItems'[Quantity]) ,DATESINPERIOD(Calendar[Date], mylastdate,-10,DAY) ) var sumSessions = CALCULATE( SUM('Sessions'[Sessions]) ,DATESINPERIOD(Calendar[Date], mylastdate,-10,DAY) ) return DIVIDE(sumQuantity, sumSessions, BLANK())Here is a screenshot of the table i used to validate the calculations:
One comment:
Wrong:
Using LastDate(...) -10 basically leads to a timeframe that contains 11 days, the lastdate (date of the current row) and 10 days before;-)Hopefully this is what you are looking for
Regards
Tom
WHOA. This is AWESOME. I never would've figured this out- THANK YOU.
-Yes, I'm planning on scrolling my dashboard, so it's a large page ;)
-I want 10 days, so I'll adjust it to -9 in the calcs. This was a sub-question I was going to ask later, so thank you!
QUESTION: The Avg Conversion Rate Simple and the Avgx Conversion Rate appear to be the same exact values. What's the difference here?
THANK YOU!!!
You sure that the Last Day of -10 is only really 9 days? I'm looking at the charts, and when it seems to be aliginging -10 with exactly 10 days...
- TomMartens8 years agoSuper UserHey
you are correct with the 10 days, i will edit my post as soon as i get back to my laptop.
Please consider to mark my post as an answer This will also help others.
Regards
Tom