Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Sort by columns in a matrix

Hello, I have a matrix in the rows, I have the names of the stations, in the columns I have the dates and in the values ​​I have the quantity that is sold for each day. I would like to be able to order from highest to lowest on any date that I can sort by rows and by total quantity, but not by columns, they know how to do it.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

If the date column is from your data table, you could create a custom column in Power Query, like below. 

 

 

=  Date.Year([Date])*10000
+ (12-Date.Month([Date]))*100
+  31-Date.Day([Date])

 

 

1.PNG

 

If the date column is from the calendar table that you create with DAX, you could try like this:

 

 

Date = 
VAR vCalendar =
    CALENDAR ( MIN ( 'Table_Calendar'[Date] ), MAX ( 'Table_Calendar'[Date] ) )
RETURN
    ADDCOLUMNS (
        vCalendar,
        "Index", YEAR ( [Date] )*10000
            + (12 - MONTH ( [Date] ))*100
            + 31 - DAY ( [Date] )
    )

 

 

 

After creating the new column, select the date column and sort by the new one.

1.gif

For more details, please see the attachment.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

Create a desc rank and make it as sort for date and try

New Date = date

Rank =Rankx(all(date),Date[date],,desc,desnse)

 

Sort_by_column.png

Anonymous
Not applicable

Hi @Anonymous ,

If the date column is from your data table, you could create a custom column in Power Query, like below. 

 

 

=  Date.Year([Date])*10000
+ (12-Date.Month([Date]))*100
+  31-Date.Day([Date])

 

 

1.PNG

 

If the date column is from the calendar table that you create with DAX, you could try like this:

 

 

Date = 
VAR vCalendar =
    CALENDAR ( MIN ( 'Table_Calendar'[Date] ), MAX ( 'Table_Calendar'[Date] ) )
RETURN
    ADDCOLUMNS (
        vCalendar,
        "Index", YEAR ( [Date] )*10000
            + (12 - MONTH ( [Date] ))*100
            + 31 - DAY ( [Date] )
    )

 

 

 

After creating the new column, select the date column and sort by the new one.

1.gif

For more details, please see the attachment.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.