Forum Discussion
Calculating rolling 52 weeks
- 5 years ago
Hi PowerMarra ,
If only rolling 52 weeks measure,try the following steps:
base data:
Step1, create new column:
weekStart = var dayOfWeek = WEEKDAY('Table'[Date]) return 'Table'[Date] - dayOfWeek +1Step2,use the below dax to create weekendnum:
runningMonthIndex = var MinWeekStart = min('Table'[weekStart]) var weekNumber = roundup((DATEDIFF(MinWeekStart , [Date] , DAY)+1) / 7,0) return weekNumberStep 3,use the below measure to get the sales 52 weeks ago:
test = CALCULATE ( SUM ( 'Table'[sale] ), FILTER ( ALL ( 'Table' ), 'Table'[runningMonthIndex] >= MAX ( 'Table'[runningMonthIndex] ) - 52 && 'Table'[runningMonthIndex] <= MAX ( 'Table'[runningMonthIndex] ) ) )Final get:
About this solutions,you could refer: https://community.powerbi.com/t5/Desktop/Rolling-52-week-sales-and-preceding-52-week-sales/m-p/720148
And if you want to roll by years,try the measurte:
test1 = CALCULATE ( SUM ( 'Table'[sale] ), DATESBETWEEN('Table'[Date], DATE(YEAR(MAX('Table'[Date]))-1,MONTH(MAX('Table'[Date])),DAY(MAX('Table'[Date]))) ,MAX('Table'[Date])) )I tested your dax, but the data did not change in the new year:
Wish it is helpful for you!
Best Regards
Lucien
PowerMarra , new column in date or calendar
new columns
Week Start date = "Date"[Date]+-1*WEEKDAY("Date"[Date],2)+1 //monday week
Week End date = "Date"[Date]+ 7-1*WEEKDAY("Date"[Date],2)
Week Rank = RANKX(all("Date"),"Date"[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all("Date"),"Date"[Year Week],,ASC,Dense) //YYYYWW format
Last 52 weeks = CALCULATE(sum("order"[Qty]), FILTER(ALL("Date"),"Date"[Week Rank]>=max("Date"[Week Rank])-52 && "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-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8
Fairly new PBI user. I am also trying to calculate a rolling 52 weeks and then a preceeding 52 weeks to calculate a % change. What formula do you suggest for the preceeding 52 weeks?