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
Hey,
please provide a link to a PBIX with sample data
Regards
Tom
Sorry- how do I do that? Make a copy of my file, and then delete out all the tables, relationships, etc- and manually fill in the data with false data?
- PBINoob8 years agoHelper I
I've searched and tried a number of things- can't seem to get this to work...
I have a Measure:
Conversion Rate =
DIVIDE((SUM(OrderItems[Quantity])), (SUM(Sessions[Sessions])))
I'd like a 10 Day Moving Average of that Measure.I'm using a Calendar Table for the time. I have something like this, but can't seem to figure this out.
DATESINPERIOD(Calendar[Date], LASTDATE(Calendar[Date]),-10,DAY)I'd really appreciate any direction here!
Thanks!
- TomMartens8 years agoSuper User
Hey,
you can start with an empty PBIX and than create a table manually using
External Data -> Enter Data from the home button or
Export the Data from a table visual check the data with Excel and make the data anonymous in Excel.
If you provide an Excel file please also provide an image of existing relationships and also provide the DAX code for existing measures (and the table the measure is associated with) and calculated columns
Regards
Tom
- PBINoob8 years agoHelper I
Here you go!
[link removed]
- TomMartens8 years agoSuper User
Hm,
following the link I got asked to login to google drive?
This will not happen!
Please make the link public, w/o the need to login to something.
Regards
Tom
- PBINoob8 years agoHelper I
Try this? It says it's a shareable link- BTW- REALLY appreciate you helping me!!!
[link removed]