How to Sort Columns in Power BI Matrix Visual?

Do you know how to sort columns in Power BI Matrix Visual? No Problem.

In this tutorial, I’ll tell you how to sort columns in the Power BI Matrix Visual and how to use DAX to sort columns in Power BI.

Also, I will explain to you how to sort column headers in the Power BI Matrix visual.

How to Sort Columns in Power BI Matrix Visual

I will tell you how to sort columns in the Power BI Matrix visual.

The below Power BI Matrix visual shows the left side matrix not sorted any column, and the right side matrix visual shows the Government column sorted in descending order. Check the screenshot below:

How to Sort Columns in Power BI Matrix Visual

Here is the Matrix visual that I am using for this example. See the screenshot below:

How do you sort columns in matrix visual

Note:

If you don’t know to create a Power BI Matrix visual, no problem. I have written a full tutorial about Create a Matrix Visual in Power BI.

1. Select the Power BI Matrix Visual you want to Sort.

how to sort column values in matrix power bi

2. Click the three dots() button on the top right corner of the visual to open the context menu.

power bi matrix sort column headers

3. In the context menu, select Sort by.

power bi matrix sort by multiple columns

Here, we can sort Country and Total Sales.

4. Select Sort ascending in the context menu. Then select Sort by -> click Total Sales.

how to sort columns in matrix table power bi

This way, we can sort Country and Total Sales (ascending/descending) in the Power BI matrix.

But how about Channel Partners, Enterprise, Government, Midmarket, and Small Business Columns?

In Power BI, we can’t sort these columns directly. But using DAX, we can Sort. To do this, follow the below steps.

1. In the Data Panel, right-click Financial Sample or click the More options () -> New measure.

Sort Columns in a Matrix with DAX in Power BI

I filter Channel Partners in the segment column using the DAX expression.

2. Enter the following DAX expression in the formula bar to filter Channel Partners. Then click the Commit button.

Channel Partners = CALCULATE([Total Sales],FILTER('Financial Sample','Financial Sample'[Segment] = "Channel Partners"))
how to sort columns in power bi matrix visual using Dax

Where:

  • Channel Partners = Name of the new Measure.
  • CALCULATE, FILTER= DAX function.
  • Total Sales = Measure.
  • Financial Sample = Name of the data set table.
  • Segment = Column name of the table.

Similarly, filter the Enterprise, Government, Midmarket, and Small Business columns using the provided DAX expressions.

Enterprise = CALCULATE([Total Sales],FILTER('Financial Sample','Financial Sample'[Segment] = "Enterprise"))
Government = CALCULATE([Total Sales],FILTER('Financial Sample','Financial Sample'[Segment] = "Government" ))
Midmarket = CALCULATE([Total Sales],FILTER('Financial Sample','Financial Sample'[Segment] = "Midmarket"))
Small Business = CALCULATE([Total Sales],FILTER('Financial Sample','Financial Sample'[Segment] = "Small Business"))

3. Now, Channel Partners, Enterprise, Government, Midmarket, and Small Business measures are shown in the Data panel.

How to Sort Columns in Matrix Power BI using Dax

4. Next, use the ‘X‘ symbol to remove Segment and Total Sales from the Columns and Values fields. Then, add Channel Partners, Enterprise, Government, Midmarket, and Small Business in the Values field.

How to Sort Matrix by Column in Descending Order in Power BI

5. Now select the Matrix visual -> Click the three dots() button on the top right corner of the visual to open the context menu.

power bi matrix sort column using DAX

6. In the context menu, select Sort by.

How to sort matrix columns in descending order in power Bi

7. Now, I want to sort Channel Partners in descending order. To do This: In the context menu, choose “Sort descending,” then select “Sort by,” and click on “Channel Partners.”

Then, you will see the values in the Channel Partners column sorted in descending order in Power BI. Check the screenshot below.

How to sort by multiple columns in Power BI

In this way, you can sort columns in Power BI Matrix Visual.

How to Sort Months Chronologically in Power BI Matrix

Now we see how to sort the month’s name in the Power BI Matrix.

I have a Date Table with columns like Date, Year, MonthName, MonthNo, and Sales(Random number). Check the screenshot below.

How to Create a Table using DAX in Power BI

Note:

If you don’t know to create a Power BI Date Table, no problem. I have written a full tutorial about How to Create a Date Table in Power BI

1. Open Power BI Desktop -> Under the Visualization panel, click Matrix Visual.

How to sort months chronologically in Power BI

2. Then drag Year into Rows, MonthName into Columns, and Sales into Values field.

Sort Months Chronologically in Power BI Matrix

3. To sort any visual, we select the visual, click the three-dot(…), and then Sort by.

power bi sort columns in matrix

Here, we can’t sort column headers in Power BI Matrix.

But we can sort in simple steps following the below steps:

4. Then go to Table view -> Select the MonthName column -> click Sort by column -> Select MonthNo.

How to Sort Months Chronologically in Power BI Matrix

5. When you navigate to the Report view, you’ll notice that the month names are sorted chronologically in the Power BI Matrix visual.

How to Conditionally Create New Table in Power BI

This way, you can sort months Chronologically in the Power BI Matrix visual.

Power BI Matrix Sort Column Headers

Now, we see how to sort months in ascending or descending order in the Power BI matrix.

In the above, the Matrix visual headers are sorted in chronological order. Now I show how to sort orders from December to January.

1. Go to Table view -> Select the MonthNo -> Then in the formula bar, put the below Dax expression

MonthNo = 13 - DateTable[Date].[MonthNo]
Sort Column Header in Matrix Table

OR

MonthNo = DateTable[Date].[MonthNo] * -1
How to Sort Columns in Power BI Matrix

2. Here, I am using the first one, then our table looks like the screenshot below.

Sorting column headers of matrix visual

3. When you go to the Report view, the month name is sorted from December to January in the Power BI Matrix visual.

Power BI Matrix Sort Column Headers

This way, you can sort matrix column headers in ascending or descending order.

Conclusion

I hope you follow the above steps to sort columns in Power BI Matrix Visual. In this tutorial, I explained how to sort columns in the Power BI Matrix Visual and how to sort months chronologically in the Power BI matrix.

Also, I explained how to sort column headers in the Power BI Matrix visual.

Moreover, you may like some more Power BI tutorials: