Livio/ July 9, 2018/ Excel, Power Query/ 1 comments

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

The Data

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: 

Download the file with the M code

Power Query

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. 

1 Comment

  1. Hi, thanks for sharing. It works. However another issue came up.

    If you try to create a chart, the first letter of the month will look slightly different.

    Check a print here: https://imgur.com/a/oNw8rCw

    I believe this happens due to the character number used (129). I tryed other numbers but without sucess. For instance numben (1), but the sort functionally was gone besides the letter be okay.

    If you have an alternative please let me know. Thanks.

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*