Forum Discussion
Sort by Year Desc and Week Desc
- 1 year ago
hi maziiw
The slicer currently supports sorting by a single column only so it is either year or week number. I would create a reversed week number column in M. You could create one in DAX by using RANKX on the week number but that would lead the a cyclic reference error as the RANKX column is referencing the week column and the latter is being sorted by the former. Here's a sample M calendar
// Query1 let StartDate = #date(2024, 1, 1), EndDate = #date(2024, 12, 31), DayCount = Duration.Days(EndDate - StartDate) + 1, Dates = List.Dates(StartDate, DayCount, #duration(1, 0, 0, 0)), CalendarTable = Table.FromList(Dates, Splitter.SplitByNothing(), {"Date"}), // Add calendar components AddYear = Table.AddColumn(CalendarTable, "Year", each Date.Year([Date]), Int64.Type), AddMonth = Table.AddColumn(AddYear, "Month", each Date.Month([Date]), Int64.Type), AddDay = Table.AddColumn(AddMonth, "Day", each Date.Day([Date]), Int64.Type), AddWeek = Table.AddColumn(AddDay, "Week Number", each Date.WeekOfYear([Date], Day.Monday), Int64.Type), // Get total number of weeks in the year LastDateOfYear = #date(2024, 12, 31), LastWeekNumber = Date.WeekOfYear(LastDateOfYear, Day.Monday), // Add Reverse Week Number AddReverseWeek = Table.AddColumn(AddWeek, "Reverse Week Number", each LastWeekNumber - [Week Number] + 1, Int64.Type), #"Changed Type" = Table.TransformColumnTypes(AddReverseWeek,{{"Date", type date}}) in #"Changed Type"No need to create a custom sort column for the year. Just sort in descending order. Note:
Alternate Display of Weeks as Year Weeks in Your Slicer
-
Year Week Sort You may already have this, but if you'd like to modify yours, use:
DAXYearWeekSort = Year('DateTable'[Date]) & "-" & Right( "0" & WEEKNUM('DateTable'[Date]), 2) -
Create a Hidden Column Add a column and mark it as "Hide in report view":
DAXYear Week Rank = 5000 - ('Date disconnected'[Year] + WEEKNUM('Date disconnected'[Date])) -
Sorting Use YearWeekRank to sort YearWeekSort.
-
Apply Sorting in the Slicer Set the Year sorting order to Descending.
-
sample output:
Alternative Sorting Option for Weeks in Your Slicer
Note: If you want the descending order to apply only to the week number and not the year, follow these steps:
~ create a column:
WeekNumberSort = 100 - WEEKNUM([Date])
Mark it as "Hide in report view".
~ Use WeekNumberSort as the sort column for the Week Number field.
~ In the slicer, add Year and Week Number, then set the Year sorting order to Descending.This will ensure that the weeks are sorted properly while maintaining the correct year order.