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
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 +1
Step2,use the below dax to create weekendnum:
runningMonthIndex =
var MinWeekStart = min('Table'[weekStart])
var weekNumber = roundup((DATEDIFF(MinWeekStart , [Date] , DAY)+1) / 7,0)
return
weekNumber
Step 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
- PowerMarra5 years agoRegular Visitor
Thank you! How would you calculate rolling 52 weeks measure for one year ago? I need to see value sales for the last 52 weeks, and last 52 weeks one year ago.
Best regards, Marianne