Power Query: Sort a Column by Another Column
This is a follow-up post regarding a solution I provided on this post on Mr.Excel forum. The OP had a table in Power Query where one of the columns contained month names in the MMM format. What he wanted to achieve is that, when he added a pivot table connected to this query, the months would show in a slicer from September to August instead of them getting sorted alphabetically. Now, if you are adding the query table to your data model, you will not need to use the solution provided in this post, the SORT BY ANOTHER COLUMN option available in the data model would be the way to go. Power Query Sort Column By Another Column
Imagine you have a table like the one below and when you add a slicer on the pivot table you want the months to go from September to August:
The M code used to perform the transformation on the Month column is:
And once you add your pivot table and slicers you will have them sorted the way you wanted:
The same technique can be applied to any other column when you cannot or do not want to use the Data Model.