Forum Discussion
vishal17081990
8 years agoHelper I
Rolling 4 Weeks Average by Weekno
Hi All,
I am new user to Power BI and trying to calculate 4 Week Rolling avg by Weeknumbers.
i have gone through quite a lot of articles and videos, tried in built DAX functions like DATESINPERIOD etc but no luck,
Since POWERBI doesnt have inbuilt function in DAX for ROlling Weekly Avg.
Roll4AVg =
Var CurrentWeek = SELECTEDVALUE(tbl_SalesDaily[tbl_Calendar.TYWN])
Var Currentyear = SELECTEDVALUE(tbl_SalesDaily[tbl_Calendar.TYN])
Var MaxWeekNo = CALCULATE(MAX(tbl_SalesDaily[tbl_Calendar.TYWN]), ALL(tbl_SalesDaily))
RETURN
AVERAGEX(
FILTER(tbl_SalesDaily,
if (CurrentWeek = 1,
tbl_SalesDaily[tbl_Calendar.TYWN] = MaxWeekNo - 3 && tbl_SalesDaily[tbl_Calendar.TYN] = Currentyear - 1,
tbl_SalesDaily[tbl_Calendar.TYWN] = CurrentWeek - 4 && tbl_SalesDaily[tbl_Calendar.TYN] = Currentyear)), [Selected Category])ended up writing this code after going through lots of articles, since Week numbers go upto 52 or 53 in some of the years and then reset to 1 for new commencing year.
Also attaching DUmmy data at below location:
https://1drv.ms/x/s!AoKR2AuKbWtQg06k3bVNAkNd-wd2
looking forward for solution...
Regards,
Vishal.
1 Reply
- Greg_DecklerCommunity Champion
I have a Rolling Weeks Quick Measure here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Rolling-Weeks/m-p/391694