Forum Discussion
Weekly data from one year to another in visual
Hi Emmy88_
1. Create a Week Sort Index in the Date table
You already have the right idea with Index, this is key.
If you don’t already have it, create
WeekIndex =
RANKX(
ALL('Date'),
'Date'[Date],
,
ASC,
DENSE
)
2. Create a Year Week display column
This is what users will see:
YearWeek =
'Date'[Year] * 100 + 'Date'[Week]
Example:
202544
202545
202601
3. Sort YearWeek by WeekIndex
In Model view
Select YearWeek
Sort by column → WeekIndex
4. Filter to Last 5 Calendar Weeks
Create a measure
Is Last 5 Weeks =
VAR MaxWeekIndex =
CALCULATE(
MAX('Date'[WeekIndex]),
ALL('Date')
)
RETURN
IF(
'Date'[WeekIndex] >= MaxWeekIndex - 4,
1,
0
)
Apply this as a visual-level filter = 1.
5. Build the Column Chart
X-axis
Date[YearWeek]
Values
Your metric
Filters
Is Last 5 Weeks = 1
Please mark it as a solution with headup if this helps you. Thank You!