Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi
I have a table and a measure is present to calculate moving average. I have a date slicer present too. Moving average of mine is for previous 3 weeks. So whn any date range is selected, the data of previous weeks is taken as 0 by the measure. This makes first 2 weeks displayed moving average not what it should be.
Table
Week Value
1 12
2 3
3 5
4 7
5 9
6 1
Moving avg for week:
1 - 12/3=4
2 - (12+3)/3=5
3 - (12+3+5)/3=6.67
4 - (3+5+7)/3=5
So on...
This is what I required as there is no data before week 1
But if I select date slicer from week 3 to week 6
I get:
Week 3 - 5/3=1.67 whereas I want it to take week 1 and week 2 in consideration too.
I want the average to be 6.67 whereas getting 1.67
Can this be achieved and if yes, thn how?
Thanks
Solved! Go to Solution.
Moving Average= CALCULATE( AVERAGEX( lineDataClosed, SUM(lineDataClosed[Closed Count])/3 ), ALL(lineDataClosed), DATESINPERIOD( lineDataClosed[Week], LASTDATE(lineDataClosed[Week]), -21, DAY ) )
Try this and let me know the result.
Have a look at the DAX statement you have used to calculate your measures. Dax Statements are context sensitive, meaning that they change their results based on slicers.
You might need to make use of an ALL() style function to tell it to consider all of the information. Its going to be tough to give you a more direct solution because ALL() will avoid every slicer, which you might not want. So you might need to use ALLEXCEPT().
@Anonymous
Moving Average= CALCULATE(AVERAGEX(lineDataClosed,sum(lineDataClosed[Closed Count])/3),DATESINPERIOD(lineDataClosed[Week],LASTDATE(lineDataClosed[Week]),-21,DAY))
This expression is giving me the result as per now. Where do I need to place All() or ALLEXCEPT() to get the desired result?
Thanks
Moving Average= CALCULATE( AVERAGEX( lineDataClosed, SUM(lineDataClosed[Closed Count])/3 ), ALL(lineDataClosed), DATESINPERIOD( lineDataClosed[Week], LASTDATE(lineDataClosed[Week]), -21, DAY ) )
Try this and let me know the result.
@Anonymous
Thanks a lot
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
135 | |
117 | |
101 | |
71 | |
61 |