Forum Discussion

abraine's avatar
abraine
Frequent Visitor
1 year ago
Solved

How to Sort by Column on a Matrix Visual

I have this Matrix Table that was built. I need it to be sorted most to least recent, as opposed to how it is right now.    I can sort by row if I use the more options button but not by column. Any...
  • ArwaAldoud's avatar
    1 year ago

    Hi abraine 

    Since Power BI does not allow direct sorting of columns in a Matrix, follow these steps:
    Option 1: Create a Sort Order Column using RANKX

    1. In Power BI Desktop, go to Data View.
    2. Open the table containing your date column.
    3. Create a new calculated column in DAX:
    4. DAX
      SortOrder = RANKX(
      ALL('YourTable'[DateColumn]),
      'YourTable'[DateColumn],
      ,
      DESC, -- Sort from most recent to oldest
      DENSE -- Ensures continuous ranking
      )
    5. In Modeling → Sort by Column, select DateColumn and sort it by SortOrder.

     

    Option 2: Use "Sort by Column" in the Modeling Tab

    1. If your table has a "Week Ending" or "Date" column, make sure it's formatted as a date.
    2. Go to Modeling → Click the DateColumn.
    3. Select Sort by Column → Choose DateColumn (or a numeric sort column if created).
    4. The matrix should now display columns in descending order (most recent first).

    Note: If your date hierarchy is enabled in the matrix, try removing the hierarchy and using the raw date column.

     

    If this response was helpful, please accept it as a solution and give kudos to support other community members