Power Query Problems

How to Sort Power Query Month Labels Chronologically in Excel

Amos GikundaAmos Gikunda Nov 3, 2026 872 views

Question details

The user needs to sort text-based month labels generated by Power Query in chronological order rather than alphabetical order within Excel PivotTables.

How to Sort Power Query Month Labels Chronologically in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
Displaying formatted month labels (such as mmm-yy) in Excel PivotTables, slicers, or charts sourced from a Power Query data model.
Observed behavior
Because the generated month labels are formatted as text, Excel sorts them alphabetically (e.g., Apr-23 before Jan-23) instead of following the chronological calendar order.
Before you start

Ensure you have access to the original Date column in your Power Query Editor, as you will need to extract the year and month components to build a numeric sorting reference.

Solution 1Recommended

Add a Numeric Year-Month Column for Sorting in Power Query

Create a custom numeric column combining the year and month to act as a hidden chronological sorting reference for your text-based month labels.

Since PivotTables treat text-formatted dates alphabetically, you must provide Excel with a separate numeric column that correctly reflects the calendar timeline. By combining the year and month into a whole number (like 202301 for January 2023), you can force Excel to sort the text labels chronologically.

1
Open the Power Query Editor

Navigate to the 'Data' tab on the Excel ribbon, select your existing dataset or query, and click 'Launch Power Query Editor' to open the transformation window.

2
Add a Custom Formula Column

Go to the 'Add Column' tab in the Power Query Editor ribbon and click 'Custom Column'. In the dialog box, name the column 'YearMonthSort' and enter the formula: =(YEAR([Date])*100)+MONTH([Date]).

3
Set the Data Type to Whole Number

Click the small data type icon located on the left side of your new 'YearMonthSort' column header and select 'Whole Number' from the dropdown menu.

4
Load the Query to the Data Model

Navigate back to the 'Home' tab, click 'Close & Load To...', choose your preferred output (such as a PivotTable Report), and make sure to check the box for 'Add this data to the Data Model'.

5
Apply Sort by Column in the Data Model

Open the Power Pivot window by clicking 'Manage Data Model' on the Data tab. Select your 'mmm-yy' text column, click 'Sort by Column' on the Home tab, and choose your new 'YearMonthSort' column as the sort reference.

Add a Numeric Year-Month Column for Sorting in Power Query
Automatic Refreshing: Once configured, this chronological sorting logic will be permanently tied to your data model. Any time another user refreshes the query, the correct sorting order will apply automatically.
Free Microsoft Office alternative

Experience Hassle-Free Data Analysis with WPS Office

Struggling with complex Power Query configurations in Microsoft Excel? WPS Office provides a lightweight, highly compatible alternative with intuitive PivotTable grouping features, allowing you to manage and sort dates chronologically without writing complex transformation formulas.

  1. 1. Open Your Data: Launch WPS Spreadsheet and open your existing dataset.
  2. 2. Insert a PivotTable: Select your data range, navigate to the 'Insert' tab, and click 'PivotTable'.
  3. 3. Group Dates Automatically: Drag your Date field to the Rows area, right-click any date, and select 'Group' to instantly organize your data by Months and Years chronologically.
Completely free and lightweight office suiteIntuitive built-in PivotTable date grouping capabilitiesSeamlessly compatible with Microsoft Excel (.xlsx) formatsFamiliar user interface requiring zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why do my month labels sort alphabetically in Excel PivotTables?

When date labels are formatted strictly as text (such as 'mmm-yy'), Excel interprets them as standard text strings rather than calendar dates. Consequently, it applies alphabetical sorting, causing April (Apr) to appear before January (Jan).

Can I fix alphabetical sorting without using Power Query?

Yes. If you are not using Power Query, you can apply Custom Number Formatting directly to your standard date values in Excel (using the format code 'mmm-yy'). Excel will display the text but retain the underlying serial date numbers, maintaining proper chronological sorting by default.

What does the formula (YEAR([Date])*100)+MONTH([Date]) do?

This formula extracts the year and month from a date and mathematically combines them into a single integer. For example, for March 2023, it multiplies 2023 by 100 to get 202300, then adds 3 for March, resulting in 202303. This integer naturally sorts in correct chronological order.

How do I access the 'Sort by Column' button in Excel?

The 'Sort by Column' button is natively available in the Power Pivot window (Data Model). You can access it by going to the 'Data' tab on the Excel ribbon and clicking 'Manage Data Model' (the green icon). In the Data View, select your text column, and the 'Sort by Column' button will be visible on the Home tab.