How to Sort Months in Power BI Matrix
Seeing your months sorted alphabetically - April, August, December, February - is one of the most common and frustrating hurdles for anyone new to Power BI. It happens because Power BI sees month names like "January" as just text and sorts them accordingly. This article will show you the exact steps to fix this and get your months displaying in the correct chronological order every single time.
Why Does Power BI Sort Months Alphabetically?
Before diving into the fix, it helps to understand why this happens. When you load your data, Power BI categorizes each column by data type: number, date, text, etc. A column containing "January," "February," and "March" is identified as a text (or "string") data type.
By default, Power BI’s sorting logic for text is alphabetical, A to Z. It has no built-in understanding that "February" should come after "January." To fix this, you need to provide an instruction that tells Power BI the correct order. You do this by associating the text-based month names with a numerical value, like a month number (1 for January, 12 for December), and then telling Power BI to use that number for sorting.
The Standard Fix: Using a "Sort by Column"
The most reliable and standard way to solve this problem is by using Power BI's built-in "Sort by Column" feature. This process involves two main steps: first, ensuring you have a numeric column for sorting (like a month number), and second, applying that column as the sort key for your month name column.
Step 1: Create a Month Number Column
Your data might already have a month number column. If it does, you can skip to Step 2. If not, don't worry - creating one is simple. You can do this using either Power Query during the data import process or with DAX inside the Power BI data model. Both methods achieve the same result.
Method A: Creating the Column in Power Query
This is a great option if you prefer to handle data transformations before they are loaded into your model. It keeps your data clean from the start.
- Open the Power Query Editor by clicking "Transform data" on the Home ribbon in Power BI Desktop.
- In the Power Query Editor, select the table that contains your date column.
- With your date column selected, go to the "Add Column" tab in the ribbon.
- Click on the "Date" dropdown menu, hover over "Month," and then select "Month."
That's it! Power Query will automatically add a new column to your table containing the corresponding month number (1-12) for each date. You can rename this column to something clear, like "Month Number." When you're done, click "Close & Apply" in the top-left corner.
Method B: Creating the Column with DAX
If you prefer to add a column directly within the Power BI environment, using Data Analysis Expressions (DAX) is the way to go.
- In Power BI Desktop, navigate to the "Data" view by clicking the table icon on the left sidebar.
- Select the table you want to modify from the "Fields" pane on the right.
- In the ribbon at the top, click on "New column." This will open the formula bar.
- Enter the following DAX formula. Be sure to replace
'YourTable'with the name of your table and[YourDateColumn]with the name of your date column.
Month Number = MONTH('YourTable'[YourDateColumn])Press Enter, and Power BI will instantaneously calculate and add the new "Month Number" column to your table.
Pro Tip: You'll also need a column with the Month's name. You can create this with DAX as well using:
Month Name = FORMAT('YourTable'[YourDateColumn], "mmmm")
Step 2: Apply the "Sort by Column" Setting
Now that you have a month name column ("January") and a month number column (1), you can connect them.
- While still in the "Data" view, click to select the column you want to sort. In this case, that's your month name column (e.g., "Month Name"). Make sure the entire column is highlighted.
- A "Column tools" tab will appear in the top ribbon. Click on it.
- Look for the "Sort by column" button in the ribbon. Click it.
- A dropdown menu will appear listing all the other columns in your table. Select the numeric column you created or already had: "Month Number."
Power BI now understands the sorting logic. When it sees "January," it checks its rule, sees it should sort by the "Month Number" column, and associates it with the value 1. When it sees "February," it associates it with 2. Nothing might visually change in the data table itself, but the logic has been applied behind the scenes.
Step 3: Verify the Sort Order in Your Matrix
The final step is to check your work. Return to the "Report" view (the canvas where you build visuals).
- Drag your Month Name column into the Rows or Columns field of a Matrix visual. Magically, the months will now be listed in their correct chronological order: January, February, March, and so on.
- If they are still not in order, click the three dots (...) in the top corner of your visual, select "Sort by," and ensure you've selected your Month Name column (which is now secretly being sorted by the Month Number).
Alternative Method: Create a Prefixed Month Column
Sometimes, modifying data models isn't an option, or you might want a quick-and-dirty solution for a simple report. In this case, you can create a single column that forces the correct alphabetical sort by adding the month number as a prefix.
The goal is to create a column with values like:
- "01 - January"
- "02 - February"
- "03 - March"
Because these text values start with numbers, a standard alphabetical sort will automatically put them in the correct chronological order.
How to Create it with DAX
You can create this custom-formatted column with a single DAX formula:
- Navigate to the "Data" view and select your table.
- Click "New column."
- Enter this DAX formula in the formula bar:
Sortable Month Name = FORMAT('YourTable'[YourDateColumn], "mm - mmmm")Let's break that formula down:
'YourTable'[YourDateColumn]is your source date.FORMAT(..., "mm - mmmm")tells DAX how to display the text.mmformats the month as a two-digit number (01, 02, 09).mmmmformats the month as its full name (January, February).
Now, simply use this new "Sortable Month Name" column in your Matrix visual instead of the original month name column. The result will sort correctly right away, without needing the "Sort by Column" feature.
Common Issues and Troubleshooting
- "Sort by Column is Grayed Out!": This typically means you haven't selected the column you want to apply the sorting rule to. Make sure you've clicked on the header of your text-based month name column first. Only then will the "Sort by column" button become active.
- "My Months Still Aren't Sorting Correctly!" The relationship for "Sort by Column" must be what's called one-to-one. For example, the text value "January" must always correspond to the number 1 - and only the number 1. If for some reason your data has "January" mapping to both 1 and 13 in different rows, the sort will fail. This usually doesn't happen with months, but it's a key concept for other types of custom sorting.
- Using a Date Table Is Best Practice: While you can add these columns to any table, the most robust and scalable way to work with dates in Power BI is to create a dedicated Date Table (also called a Calendar Table). This single table holds all your date-related information (Year, Quarter, Month Name, Month Number, Day of Week, etc.) and connects to your other data tables. It centralizes all your sorting logic and time-based calculations, making your reports more powerful and easier to maintain.
Final Thoughts
Correcting the alphabetical sort order of months is a fundamental skill in Power BI that turns frustrating visuals into clean, intuitive reports. By using the "Sort by Column" feature with a dedicated numeric column, you are giving Power BI the clear instructions it needs to present your time-based data logically and professionally.
We know that managing these small but critical details in reporting tools can consume hours that should be spent on strategy. It's why we created Graphed. Our platform is designed to handle the analytical heavy lifting for you. When you connect your data sources and simply ask for a "funnel analysis comparing Facebook Ads spend vs. revenue by campaign for the last 6 months," it automatically knows how to render the data - with months and everything else sorted correctly - without you ever needing to create a helper column or dive into a data model. You just get the answer you need in an instant.
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.