Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi,
Does anyone know how to reverse date hierarchy?
I have added the date into a matrix visual in the 'Columns' section but the years are showing from 2021 upwards, however I want the most recent year to be dipslayed first?
Solved! Go to Solution.
Hi @ShivGC
Matrix can be sorted only by the measure or row categories. Column categories are either sorted alphabetically or by using a custom column sort. You can rank the year in your dates table to get the reverse sort.
Year Sort =
RANKX(ALL(Dates[Year]), Dates[Year],,DESC,Dense)
As the rank calc column is referencing the year column, year cannot be sorted directly by this column as this will cause circular dependency.
Your alternative is to create another calculated column referencing the original year column, custom sort that instead and then use it in your viz.
Alternatively and if you are using DAX calendar, you can the sort column directly in to the table itself and not as a calc column. Here's a sample DAX calendar with a year sort/rank column built-in
Dates =
VAR __MIN =
DATE ( 2022, 1, 1 )
VAR __MAX =
TODAY()
VAR __BASE =
CALENDAR ( __MIN, __MAX )
VAR __RESULT =
ADDCOLUMNS (
ADDCOLUMNS (
__BASE,
"Year", YEAR ( [Date] ),
"Month Long", FORMAT ( [Date], "mmmm" ),
"Month Short", FORMAT ( [Date], "mmm" ),
"Month Number", MONTH ( [Date] ),
"Month and Year", FORMAT ( [Date], "mmm-yy" ),
"YYYYMM", FORMAT ( [Date], "YYYYMM" ),
"Quarter", "Q" & QUARTER ( [Date] ),
"Day of Week Long", FORMAT ( [Date], "dddd" ),
"Day of Week Short", FORMAT ( [Date], "ddd" ),
"Day Sort", WEEKDAY ( [Date], 1 ),
"Week of Year", WEEKNUM ( [Date] ),
"Week Ending Saturday",
VAR __DAY =
WEEKDAY ( [Date] ) - 7
RETURN
[Date] - __DAY,
"Start of Month", EOMONTH ( [Date], -1 ) + 1,
"End of Month", EOMONTH ( [Date], 0 )
),
"FY",
IF ( [Month Number] >= 7, [Year] + 1, [Year] ),
"Month FY", [Month Short],
"Month Sort FY",
IF ( [Month Number] > 6, [Month Number] - 6, [Month Number] + 6 ),
"Week Num", WEEKNUM([Date]),
"Day Number", DATEDIFF ( DATE ( YEAR ( [Date] ), 1, 1 ), [Date], DAY ) + 1,
"Month and Day", FORMAT([Date], "mm-dd"),
"Week Ending Sunday",
[Date]
+ MOD ( 1 - WEEKDAY ( [Date] ) + 7, 7 ),
"Week Starting Monday", [Date] - WEEKDAY ( [Date], 3 ),
"Year Rank", RANKX ( DISTINCT( __BASE ), YEAR ( [Date] ), , DESC, DENSE )
)
RETURN
__RESULT
Proud to be a Super User!
Hi @ShivGC
Matrix can be sorted only by the measure or row categories. Column categories are either sorted alphabetically or by using a custom column sort. You can rank the year in your dates table to get the reverse sort.
Year Sort =
RANKX(ALL(Dates[Year]), Dates[Year],,DESC,Dense)
As the rank calc column is referencing the year column, year cannot be sorted directly by this column as this will cause circular dependency.
Your alternative is to create another calculated column referencing the original year column, custom sort that instead and then use it in your viz.
Alternatively and if you are using DAX calendar, you can the sort column directly in to the table itself and not as a calc column. Here's a sample DAX calendar with a year sort/rank column built-in
Dates =
VAR __MIN =
DATE ( 2022, 1, 1 )
VAR __MAX =
TODAY()
VAR __BASE =
CALENDAR ( __MIN, __MAX )
VAR __RESULT =
ADDCOLUMNS (
ADDCOLUMNS (
__BASE,
"Year", YEAR ( [Date] ),
"Month Long", FORMAT ( [Date], "mmmm" ),
"Month Short", FORMAT ( [Date], "mmm" ),
"Month Number", MONTH ( [Date] ),
"Month and Year", FORMAT ( [Date], "mmm-yy" ),
"YYYYMM", FORMAT ( [Date], "YYYYMM" ),
"Quarter", "Q" & QUARTER ( [Date] ),
"Day of Week Long", FORMAT ( [Date], "dddd" ),
"Day of Week Short", FORMAT ( [Date], "ddd" ),
"Day Sort", WEEKDAY ( [Date], 1 ),
"Week of Year", WEEKNUM ( [Date] ),
"Week Ending Saturday",
VAR __DAY =
WEEKDAY ( [Date] ) - 7
RETURN
[Date] - __DAY,
"Start of Month", EOMONTH ( [Date], -1 ) + 1,
"End of Month", EOMONTH ( [Date], 0 )
),
"FY",
IF ( [Month Number] >= 7, [Year] + 1, [Year] ),
"Month FY", [Month Short],
"Month Sort FY",
IF ( [Month Number] > 6, [Month Number] - 6, [Month Number] + 6 ),
"Week Num", WEEKNUM([Date]),
"Day Number", DATEDIFF ( DATE ( YEAR ( [Date] ), 1, 1 ), [Date], DAY ) + 1,
"Month and Day", FORMAT([Date], "mm-dd"),
"Week Ending Sunday",
[Date]
+ MOD ( 1 - WEEKDAY ( [Date] ) + 7, 7 ),
"Week Starting Monday", [Date] - WEEKDAY ( [Date], 3 ),
"Year Rank", RANKX ( DISTINCT( __BASE ), YEAR ( [Date] ), , DESC, DENSE )
)
RETURN
__RESULT
Proud to be a Super User!
Hi @ShivGC
Check all these post
I hope you will find solution in above post.
I hope I answerd your question!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
143 | |
87 | |
67 | |
48 | |
45 |
User | Count |
---|---|
211 | |
83 | |
76 | |
61 | |
53 |