Forum Discussion
mrclay823
1 year agoNew Member
Rolling 52 weeks.
Hi all, I want to create this visual in PBI for our [sales] measure (pretend that w.2 is last week and for 52 weeks. So, one line to show the sales rolling 52 weeks and one to show the same p...
Poojara_D12
Super User
1 year agoHi mrclay823
To create this rolling 52-week comparison visual in Power BI with one line for the last 52 weeks and another for the same period the previous year, you can use DAX measures. Since you cannot modify column formats or create new columns, we will work with measures only.
This measure will sum the sales for the last 52 weeks dynamically:
Sales Rolling 52 Weeks =
VAR MaxWeek = MAX('Date'[Week]) -- Get the latest selected week
VAR MaxYearWeek = MAX('Date'[YearWeek]) -- Get the latest YearWeek in context
RETURN
CALCULATE(
SUM(Sales[SalesAmount]),
'Date'[YearWeek] <= MaxYearWeek &&
'Date'[YearWeek] > MaxYearWeek - 52 -- Include the last 52 weeks
)
To compare the same period from the previous year, shift the YearWeek by 52 weeks back:
Sales Rolling 52 Weeks LY =
VAR MaxWeek = MAX('Date'[Week])
VAR MaxYearWeek = MAX('Date'[YearWeek])
RETURN
CALCULATE(
SUM(Sales[SalesAmount]),
'Date'[YearWeek] <= MaxYearWeek - 52 &&
'Date'[YearWeek] > MaxYearWeek - 104 -- Shift 52 weeks back
)
- mrclay8231 year agoNew Member