Forum Discussion
rpinxt
Solution Sage
1 year agoSorting on columns in a matrix
Pic will make it clear : What I wanted is Year-week in a descending order. At leat putting Year-Month above is will get me the descending part because YM is sorted by YM- : Dim_Date = A...
- 1 year ago
Hi rpinxt
The matrix visual does not offer an option to sort columns in descending or ascending order directly. Columns are sorted either alphabetically or based on custom sorting in ascending order. To achieve your desired sorting, you will need to create a custom sort column. Please refer to the example below:
DatesTable = VAR _base = ADDCOLUMNS ( CALENDAR ( DATE ( 2024, 1, 1 ), TODAY () ), "YYYY-MM", FORMAT ( [Date], "YYYY-MM" ), "Year Week", YEAR ( [Date] ) & "-" & FORMAT ( WEEKNUM ( [Date] ), "00" ) ) RETURN ADDCOLUMNS ( _base, "Year-Month Sort", RANKX ( _base, [YYYY-MM],, DESC, DENSE ), "Year-Week Sort", RANKX ( _base, [Year Week],, DESC, DENSE ) )
danextian
Super User
1 year agoHi rpinxt
The matrix visual does not offer an option to sort columns in descending or ascending order directly. Columns are sorted either alphabetically or based on custom sorting in ascending order. To achieve your desired sorting, you will need to create a custom sort column. Please refer to the example below:
DatesTable =
VAR _base =
ADDCOLUMNS (
CALENDAR ( DATE ( 2024, 1, 1 ), TODAY () ),
"YYYY-MM", FORMAT ( [Date], "YYYY-MM" ),
"Year Week",
YEAR ( [Date] ) & "-"
& FORMAT ( WEEKNUM ( [Date] ), "00" )
)
RETURN
ADDCOLUMNS (
_base,
"Year-Month Sort", RANKX ( _base, [YYYY-MM],, DESC, DENSE ),
"Year-Week Sort", RANKX ( _base, [Year Week],, DESC, DENSE )
)