Data Import & Export

How to Filter Excel Data by Code and Sort Months Chronologically

Natalie TaylorNatalie Taylor Nov 10, 2026 868 views

Question details

The user needs to extract records matching a specific code from a dataset and sort the resulting data by calendar month (January to December), retaining all duplicates.

How to Filter Excel Data by Code and Sort Months Chronologically
Product
Excel
Device & OS
not provided
Scenario
Organizing and extracting specific categorical data while maintaining a strict chronological calendar month order instead of alphabetical order.
Observed behavior
Data needs to be filtered by a cell reference and automatically arranged in chronological month order (Jan-Dec) with grouped details intact.
Before you start

Ensure your month data is consistently formatted (e.g., three-letter abbreviations like 'JAN' or full names) so the formulas or Power Query can correctly identify and sort them.

Solution 1Recommended

Use Dynamic Array Formulas in Excel 365

Leverage Excel 365's powerful dynamic arrays to filter and stack data automatically in calendar-month order.

If you are using Excel 365, you can utilize modern array functions like REDUCE, FILTER, and VSTACK. This method allows you to instantly extract and sort your dataset without relying on manual filtering or complex macros.

1
Select Destination Cell

Click on the top-left cell where you want the filtered and sorted data to appear.

2
Input Dynamic Formula

Enter the following formula, adjusting the ranges (A3:A82, B3:D82) and the criterion cell (G2) to match your dataset: =DROP(REDUCE("",{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"},LAMBDA(a,x,IFERROR(VSTACK(a,FILTER(CHOOSECOLS(B3:D82,3,1,2),(A3:A82=G2)*(D3:D82=x),x)),""))),1)

3
Execute Formula

Press Enter. The formula will automatically spill the matching records down the rows, grouped chronologically by month.

Use Dynamic Array Formulas in Excel 365
Version Compatibility: This solution requires an Excel 365 subscription or Excel for the Web, as it relies on functions (REDUCE, VSTACK, CHOOSECOLS, DROP) that are not available in older versions.
Advanced Data Management

Easily Filter and Sort Data in WPS Spreadsheet

WPS Spreadsheet provides robust data manipulation tools, including advanced filtering, custom sorting, and modern array compatibility to help you organize complex datasets effortlessly.

  1. 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your workbook containing the data you wish to filter.
  2. 2. Apply AutoFilter: Select your dataset, navigate to the 'Data' tab on the ribbon, and click 'AutoFilter'. Use the drop-down on your target column to filter by the specific code.
  3. 3. Use Custom Sort for Months: Click the filter arrow on your Month column, select 'Custom Sort', and choose the chronological month list (Jan, Feb, Mar...) from the Custom Lists options to sort the results instantly.
Fully compatible with Microsoft Excel formulas and formats (.xlsx)Built-in custom sort feature to easily arrange months chronologically without complex formulasLightweight application with high performance for massive datasetsFree to use with a familiar, highly intuitive user interface
microsoft office alternative - wps office

Frequently Asked Questions

Why does Excel sort months alphabetically instead of chronologically?

Excel treats month names (like 'Jan' or 'January') as basic text strings by default. To sort them chronologically, you must use a Custom Sort list, convert them to actual serial dates, or use a helper column containing month numbers.

Can I use the REDUCE and VSTACK formula in older Excel versions?

No, functions like REDUCE, VSTACK, and CHOOSECOLS are exclusive to Excel 365 and Excel for the Web. For older versions like Excel 2016 or 2019, the Power Query method or manual helper columns are the best alternatives.

How do I create a custom sort list for months in my spreadsheet?

Go to File > Options > Advanced > Edit Custom Lists. You can manually type the months in chronological order here. Once saved, you can use the standard Sort dialog to arrange your text-based months correctly.