Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi,
I need help in building 4 week rolling average for "Net Change in Price and Cost" with below sample data
Change in Price, Change in Cost and Net Change in Price and Cost are all 3 measures.
Net Change in Price and Cost = Change in Price - Change in Cost
I do have separate date table and the above data shows weekly data and my report has Invoice Date as Filter.
I need to calculate rolling 4 week average, here the tweak is that for first week start date 12/07 rolling average should be same while for next 12/14 it should (-4.80% + 0.18%)/2 = -2.31%
for 12/21 it should be (-4.80% + 0.18% - 0.04%)/3 = -1.55%
for 12/28 it should be (-4.80% + 0.18% - 0.04% -0.65%)/4 = -1.33%
for 01/04 it should be (0.18% - 0.04% -0.65% +1.03%)/4 = 0.13%
as shown below
I have created below DAX but its not working as expected
Solved! Go to Solution.
Hi @apatwal ,
Here's my solution.
1.Create a index measure
Index =
CALCULATE (
COUNT ( 'Date'[Week Start Date] ),
FILTER (
ALL ( 'Date' ),
[Week Start Date] <= MAX ( 'Table'[Week Start Date] )
)
)
2.Create another measure to get the rolling 4 week average.
Rolling 4 week average =
CALCULATE (
AVERAGEX ( 'Table', [Net Change in Prce and Cost] ),
FILTER (
ALL ( 'Table' ),
[Index] <= MAXX ( 'Table', [Index] )
&& [Index]
>= MAXX ( 'Table', [Index] ) - 3
)
)
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @apatwal ,
Here's my solution.
1.Create a index measure
Index =
CALCULATE (
COUNT ( 'Date'[Week Start Date] ),
FILTER (
ALL ( 'Date' ),
[Week Start Date] <= MAX ( 'Table'[Week Start Date] )
)
)
2.Create another measure to get the rolling 4 week average.
Rolling 4 week average =
CALCULATE (
AVERAGEX ( 'Table', [Net Change in Prce and Cost] ),
FILTER (
ALL ( 'Table' ),
[Index] <= MAXX ( 'Table', [Index] )
&& [Index]
>= MAXX ( 'Table', [Index] ) - 3
)
)
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Somehow it didn't work for me. Index part didn't work. I also do not have week start date in sales table. Is there anyway i can connect with you to fix the issue i have. Thank you so much. Appreciate !
Thanks so much. This really worked for me. Hope to learn a lot from these community
@apatwal , Create a week rank on week start date or on week year
new columns
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
Avg of rolling 4 weeks , assuming [Net Change in Price and Cost] is measure
Last 4 weeks = CALCULATE(Averagex(Values('Date'[Week Rank]), [Net Change in Price and Cost]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))
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-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8
Hi @amitchandak
thanks for your reply!
But looks there is some issue in calculations
Used same DAX provided by you..
User | Count |
---|---|
20 | |
14 | |
11 | |
8 | |
6 |
User | Count |
---|---|
23 | |
23 | |
20 | |
15 | |
10 |