Forum Discussion
Moving Average nbased on week Nuber from the Table
Hi All,
I have a querry on 3 months moving average. I have a data based on the weeks where i need to calculate the 3 months moving average.
i have tried with the below formulas but seems not to be working.
Data in the table:
| ID's | Value | Close date Week |
| 7599840 | 35678.5 | 1 |
| 80900 | 2140.71 | 2 |
| 80900 | 24974.95 | 3 |
| 80900 | 24974.95 | 4 |
| 80900 | -24974.95 | 5 |
| 7599840 | 14271.4 | 5 |
| 7599840 | 28542.8 | 6 |
| 7599840 | 214071 | 7 |
| 7599840 | -214071 | 8 |
| 80900 | 24261.38 | 9 |
| 7599840 | 214071 | 10 |
| 188000 | 35678.5 | 11 |
| 1011010 | 4994.99 | 12 |
| 1011010 | 4994.99 | 13 |
| 758080 | 16055.33 | 14 |
| 80900 | -4102.23 | 15 |
| 80900 | 4102.23 | 16 |
| 80900 | 4102.23 | 17 |
| 14505 | 14271.4 | 18 |
Pivoted:
| Close date Week | Sum of Value | 3 Months MA |
| 1 | 35678.5 | 35678.5 |
| 2 | 2140.71 | 2140.71 |
| 3 | 24974.95 | 24974.95 |
| 4 | 24974.95 | 35678.5 |
| 5 | -10703.55 | 2140.71 |
| 6 | 28542.8 | 24974.95 |
| 7 | 214071 | 35678.5 |
| 8 | -214071 | 2140.71 |
| 9 | 24261.38 | 24974.95 |
| 10 | 214071 | 35678.5 |
| 11 | 35678.5 | 2140.71 |
| 12 | 4994.99 | 24974.95 |
| 13 | 4994.99 | 35678.5 |
| 14 | 16055.33 | 2140.71 |
| 15 | -4102.23 | 24974.95 |
| 16 | 4102.23 | 35678.5 |
| 17 | 4102.23 | 2140.71 |
| 18 | 14271.4 | 24974.95 |
I have created the below formula. Kindly check and let me know if there are anything wrong in it.
Regards,
Ranjan
Hi, RanjanThammaiah
Based on your description, I assume that your requirement is to calculate the average value of previous three weeks. I created data as follows.
Table:
You may create a measure as follows.
3 weeks MA = var _week = SELECTEDVALUE('Table'[Close date Week]) return IF( _week>=4, CALCULATE( AVERAGE('Table'[Value]), FILTER( ALLSELECTED('Table'), 'Table'[Close date Week]>=_week-3&& 'Table'[Close date Week]<=_week-1 ) ), 0 )Result:
If I misunderstand your thoughts, please show me your expected result. Do mask sensitive data before uploading. Thanks.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- Greg_Deckler
Community Champion
See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008 - v-alq-msft
Community Support
Hi, RanjanThammaiah
Based on your description, I assume that your requirement is to calculate the average value of previous three weeks. I created data as follows.
Table:
You may create a measure as follows.
3 weeks MA = var _week = SELECTEDVALUE('Table'[Close date Week]) return IF( _week>=4, CALCULATE( AVERAGE('Table'[Value]), FILTER( ALLSELECTED('Table'), 'Table'[Close date Week]>=_week-3&& 'Table'[Close date Week]<=_week-1 ) ), 0 )Result:
If I misunderstand your thoughts, please show me your expected result. Do mask sensitive data before uploading. Thanks.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.