How to Sort Matrix Column Headers in Power BI?

Have you ever tried to sort column headers in a Power BI matrix visual? There is no sort option available in the Matrix visual to sort the column headers, like row sorting.

While researching this, I discovered that there was no clear explanation in one place. I thought I would share my experience in this tutorial clearly.

In this tutorial, I will explain how to sort a matrix table column header in Power BI Desktop.

Sort Column Headers in Matrix Table Power BI [Sort Date Columns Descending]

I have created a Matrix visual in my Power BI report, with the ‘Sales‘ data, where the Rows represent the ‘Product‘, Columns represent the ‘Year‘ field, and Values represent the ‘Sales Amount‘.

You can refer to the image below, where the column headers [Year] are in the order of 2022, 2023, 2024, and 2025.

Power BI Sort Column headers in matrix

Now, my requirement is to sort the matrix table by column headers in the order of [2025, 2024, 2023, 2022].

Since we cannot sort the column headers by any sort option, we can create a custom sort using the Index column. First, we need to create a table with Year values (2022, 2023, 2024, 2025) and an index column.

Follow the steps below:

  1. To create a table in Power BI Desktop, click the Enter Data icon on the Home tab. Then, the ‘Create table‘ window will open, with all the years in a table. Click on the ‘Edit‘ button.
Power BI Sort Matrix by column Headers
  1. Then, it will navigate to another page, where you need to add an Index column to the table. Click on the Add Column tab -> Click on the drop-down of Index Column. Select From 1 option. You can refer to the screenshot below:
Power BI matrix Sort column headers

Now, the table will be created with the years along with the index values, and it will be present under the Data Pane.

Sort Matrix by Column Headers Power BI

Then, exit the Power Query Edit mode.

  1. After that, click on the ‘Table view‘ on the left side, select ‘Year‘ values in the column in the new table. Go to ‘Column tools‘ tab -> Select ‘Sort by column‘ option -> Select Index.
Power BI Sort Matrix table column headers
Sort Column Header in Matrix Table Power BI

Thus, the Year values will be sorted according to their index numbers. Therefore, we need to establish a relationship between the Matrix table and the support table [Index] that we have created.

  1. In the final step, click on the Model View tab, then click on ‘Manage Relationship‘ and add a relationship between the Matrix table and the Support table as shown in the image below.
    • From Table – Select your Matrix table.
    • To Table – Select the support table that you have created.
    • Cardinality – Choose Many-to-one(*:1).

Select the Year column present in the support table, and it will show the cardinality option. Click on the Save button.

Sort Matrix Table Column Headers Power BI

Thus, the relationship will be established between them.

  1. Now, return to the Report view, select the Matrix table, and replace the ‘Replace Columns‘ value with ‘Year‘ from the support table. Have a look at the image below.
Sort Power BI Matrix Column headers
  1. Now, it will display the sorting order of column headers in the matrix visual in a specific order, such as [2025, 2024, 2023, 2022]. Have a look at the reference image below.
Matrix Table Column Header Custom Sorting

This is how to sort the column headers in the matrix table in Power BI.

I hope you found this tutorial helpful. If you have any queries, mention them in the comments section below.

You may like the following tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…