Forum Discussion
MOVING AVERAGE -3 weeks
Hi,
I am a fair user of Power BI but struggling with creating a measure for calculation of Moving avarage across weeks
Below is a example of Matrix visual in Power BI.
I want to use a measure to calculate the moving average of demand across 3 weeks.
Moving average Demand, Measure in below example should be for week 6 = 60/3=20, Week 7= 50/3 = 16.6 and so on.
The measure will be used further to calculate days. Constraints as below Data is from direct query.
- Some slicers are already selected
- Year and week in text format
- Field available in Direct query in date format is (First day of the week)
- Fiels available for index weeks which is filtered for avlues between 0 &11
- Formula tried MAD -3 weeks = CALCULATE( AVERAGEX(ZBE_12WEEK_DEMAND_AP,ZBE_12WEEK_DEMAND_AP[Demand in To]), DATESINPERIOD( ZBE_12WEEK_DEMAND_AP[First Day of Week], LASTDATE(ZBE_12WEEK_DEMAND_AP[First Day of Week]), 21, DAY ) )
- Result of above formuala is the same demand as shown.
Kindly help to resolve .
| Year Week | 2021.06 | 2021.07 | 2021.08 | 2021.09 | 2021.1 | 2021.11 | 2021.12 | 2021.13 | 2021.14 |
| Material A | |||||||||
| Demand | 40 | 0 | 20 | 30 | 0 | 10 | 40 | 0 | 30 |
| Stock | 20 | 20 | 10 | 30 | 20 | 10 | 20 | 20 | 10 |
| Days | 4 | #DIV/0! | 4 | 7 | #DIV/0! | 7 | 4 | #DIV/0! | 2 |
| Material B | |||||||||
| Demand | 50 | 0 | 20 | 30 | 0 | 10 | 50 | 0 | 30 |
| Stock | 25 | 25 | 10 | 30 | 25 | 10 | 25 | 25 | 10 |
| Days | 4 | #DIV/0! | 4 | 7 | #DIV/0! | 7 | 4 | #DIV/0! | 2 |
Regards
Joshi M
Joshi_M , refer if my week on blog can help
Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8example
Last 3 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-3 && 'Date'[Week Rank]<=max('Date'[Week Rank])))/3
Yes I modified the formula in my Case as below
Next 3 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]<=max('Date'[Week Rank])+3 && 'Date'[Week Rank]>=max('Date'[Week Rank])))/3
It is working
Many Thanks
Regards
2 Replies
- amitchandakSuper User
Joshi_M , refer if my week on blog can help
Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8example
Last 3 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-3 && 'Date'[Week Rank]<=max('Date'[Week Rank])))/3
- Joshi_MHelper I
Yes I modified the formula in my Case as below
Next 3 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]<=max('Date'[Week Rank])+3 && 'Date'[Week Rank]>=max('Date'[Week Rank])))/3
It is working
Many Thanks
Regards