How to Sort Columns in Power BI Matrix
Building a matrix in Power BI can feel like a victory, letting you slice and dice your data beautifully for clear analysis. But just when you think you’ve got it perfect, you notice the columns are completely out of order - months displaying alphabetically (April, August, December...) instead of chronologically. This article will show you exactly how to take control and sort your matrix columns logically, whether it’s by month, day of the week, or any other custom order you need.
Why Power BI Sorts Columns Alphabetically By Default
Before jumping into the solution, it’s helpful to understand the "why" behind the problem. When you drop a text field like "Month Name" or "Day of the Week" into the Columns well of a matrix, Power BI doesn't automatically know its chronological significance. To Power BI, "January" is just a word that starts with "J" and "Monday" is just a word that starts with "M." It logically defaults to sorting text fields in alphabetical order (A-Z).
This is the root of the issue for time-based data. While alphabetically correct, an A-Z sort order for months or days makes trend analysis nearly impossible and presents a confusing picture to anyone reading your report. To fix this, you need to tell Power BI the correct order by giving it a numerical placemarker to follow, which we will do with a "helper column."
The Solution: Using "Sort by Column"
The secret to custom sorting in Power BI lies in a powerful little feature called Sort by Column. The process involves creating a separate "helper" column in your data table that contains the numerical order you want to follow. Then, you tell Power BI to use this numerical column to sort your text-based column.
For example, to sort months correctly, we will create a column with the month number (1 for January, 2 for February, etc.). Then we'll select our "Month Name" column and use the "Sort by Column" feature to tell it to follow the order of our new "Month Number" column.
Here’s the step-by-step universal process:
- Create a sort-order "helper column." This will be a column of whole numbers that defines the sorting sequence (e.g., 1, 2, 3...). You can create this in Power Query Editor during data import or by using DAX to create a new calculated column. We will cover DAX examples below.
- Go to the Data view in Power BI Desktop (the second icon on the left-hand navigation pane that looks like a table).
- Select the column you want to sort. Click on the header of the text column whose visible order you want to fix (e.g., 'MonthName').
- Click the "Sort by Column" button. You'll find this on the "Column tools" tab that appears in the top ribbon when you select a column.
- Choose your helper column. A dropdown will appear. Select the numerical helper column you created in step one (e.g., 'MonthNumber').
That's it. Power BI will now use the numerical values in your helper column to set the sort order for your text column in all visuals, including your matrix. Don't worry if it sounds abstract, let's walk through some practical examples.
Practical Example #1: How to Sort Columns by Month Name
This is the most common use case. You have a matrix showing sales by month, but the months are all wrong. Let's assume you have a 'Sales' table with a date column called 'OrderDate'.
Step 1: Create a "Month Name" Column
If you don't already have one, first you need a column with the month name. In the Data view, with your 'Sales' table selected, click "New column" from the ribbon and enter this DAX formula:
MonthName = FORMAT([OrderDate], "MMMM")
Step 2: Create a Numeric "Month Number" Helper Column
Next, we create the column that defines the sort order. Click "New column" again and enter this DAX formula:
MonthNumber = MONTH([OrderDate])
This formula extracts the number of the month (1 for January, 12 for December) from your date column. Your table now has both the name of the month and its corresponding numerical order.
Step 3: Apply the "Sort by Column" Logic
Now, follow the final steps we outlined earlier:
- While still in the Data view, click to select your 'MonthName' column.
- From the "Column tools" ribbon, click "Sort by Column."
- From the dropdown, select your 'MonthNumber' column.
Power BI will work for a moment, and then… magic! Go back to your Report view. Your matrix columns should now be perfectly sorted: January, February, March, and so on. Any other visual using the 'MonthName' field will also use this new sort order.
Practical Example #2: How to Sort by Day of the Week
The exact same logic applies to sorting by the day of the week. Let’s say you want to see which day drives the most traffic or sales, but Power BI shows Friday, Monday, Saturday, Sunday... We'll use columns for the day name and its numerical counterpart. We'll use the same 'OrderDate' column from our 'Sales' table.
Step 1: Create Your Text and Number Columns
First, create the day name column with this DAX formula:
DayName = FORMAT([OrderDate], "dddd")
Next, create the numerical helper column to define our week's order (Monday as 1, Sunday as 7). Use this DAX formula:
DayOfWeekNumber = WEEKDAY([OrderDate], 2)
Quick Tip: The '2' in the WEEKDAY function tells DAX to treat Monday as the first day of the week (1) and Sunday as the last (7). If you wanted Sunday to be 1, you would use WEEKDAY([OrderDate], 1).
Step 2: Apply the Sort Logic
- Select your 'DayName' column in the Data view.
- Click "Sort by Column."
- Choose your 'DayOfWeekNumber' column.
Your visuals will now correctly display days in chronological order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
Practical Example #3: Sorting a Non-Time-Based Custom Order
This technique isn't just for dates. You can use it to define any custom order you want. Imagine you are analyzing sales of t-shirts and you want your columns to be sorted by size: Small, Medium, Large, Extra Large, not alphabetically (Extra Large, Large, Medium, Small). Assume you have your sales data and a 'T-Shirt Size' column.
Step 1: Make a Numerical Helper Column
This time, since Power BI has no built-in way to "know" t-shirt sizes, you have to define the order manually. A SWITCH function in DAX is perfect for this. Click "New Column" and enter this formula:
SizeSortOrder = SWITCH( TRUE(), [T-Shirt Size] = "Small", 1, [T-Shirt Size] = "Medium", 2, [T-Shirt Size] = "Large", 3, [T-Shirt Size] = "Extra Large", 4, 5 // A default number for any other sizes )
This formula checks the value in your 'T-Shirt Size' column and assigns a number based on the order you defined.
Step 2: Apply the Sort
- Select your textual 'T-Shirt Size' column.
- Click "Sort by Column."
- Select your new 'SizeSortOrder' column.
Your matrix will now order the columns logically by size, making the report much easier to understand at a glance.
Troubleshooting Common Issues
Sometimes, even after following the steps, your sort order doesn't behave as expected. Here are a couple of common pitfalls and their solutions:
- The sort still isn't working: After applying "Sort by Column," Power BI has to re-process the visuals. Sometimes a simple click to and from the report page or even closing and reopening the file will force the visual to update with the correct sort order. Also, double-check that both your text column and your helper column are in the same table.
- My numbers are showing up as a sum: If your helper column (like 'MonthNumber') appears in a visual and gets summed up, it's because Power BI defaults to summarizing number fields. Click on the helper column in the Fields pane and in the "Column tools" tab, find the "Summarization" option and set it to "Don't summarize." This is good practice for all your helper columns.
- "A circular dependency was detected" error: This DAX error can occur if you create a complex chain of calculated columns that refer to one another. The simplest way to avoid this is to create your helper columns as early as possible in your data preparation process, ideally using the Power Query Editor rather than DAX if your logic gets very complex.
Final Thoughts
Sorting Power BI matrix columns isn't intuitive at first, but mastering the "Sort by Column" feature gives you complete control over your reports. By pairing a text column with a custom-defined numerical helper column, you can order your visuals logically and tell a much clearer story with your data.
While mastering these tricks in Power BI is a valuable skill, we know it represents the kind of time-consuming data wrangling that pulls you away from actual analysis. At Graphed, we built an AI data analyst to eliminate these hurdles. Instead of creating helper columns and digging through menus, you can connect your data sources and just ask for what you want in plain English, like, "Show me our total sales by month this year as a bar chart" - perfectly sorted in seconds. Give Graphed a try and turn hours of report building into a 30-second conversation.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.