Forum Discussion
tl1234
Helper I
8 months agoAssign Week Number to a Single Month Across Multiple Years
Hello, I'm trying to make a comparison across multiple years of the number of people that stayed at our facility. The below snips show the query I made. The below is my code. ...
- 8 months ago
Hi , tl1234
My recommended approache is instead of relying on month and week columns from your fact tables, create a Date Dimension with:
- Continuous dates.
- Columns for Year, Month, Month Name, Week Number, and optionally Year-Week (e.g., 2025-W01).
- Mark this table as Date Table in Power BI.Then:
- Relate your combined table to this Date Table using a proper date key.
- Use the hierarchy from the Date Table in visuals (Year → Month → Week).
This ensures consistent sorting and avoids the “ugly” misalignment.You can generate this Date Table in Power Query easily:
let StartDate = #date(2022, 1, 1), EndDate = #date(2025, 12, 31), Dates = List.Dates(StartDate, Duration.Days(EndDate - StartDate)+1, #duration(1,0,0,0)), Table = Table.FromList(Dates, Splitter.SplitByNothing(), {"Date"}), AddColumns = Table.TransformColumns(Table, {{"Date", type date}}), AddYear = Table.AddColumn(AddColumns, "Year", each Date.Year([Date])), AddMonth = Table.AddColumn(AddYear, "Month", each Date.Month([Date])), AddMonthName = Table.AddColumn(AddMonth, "Month Name", each Date.MonthName([Date])), AddWeek = Table.AddColumn(AddMonthName, "Week Number", each Date.WeekOfYear([Date])) inIf this response was helpful in any way, I’d gladly accept a 👍much like the joy of seeing a DAX measure work first time without needing another FILTER.
Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop 🌀.
anilelmastasi
Super User
8 months agoHello tl1234 ,
Weeks do not belong to months, they belong to dates. You should use WeekStartDate and take week after. You can add columns as week of start and week.
If this solved your issue, please mark it as the accepted solution. ✅
tl1234
Helper I
8 months agoHello,
Sorry I don't understand your reponse. Can you please elaborate?
Thank-you!