Power Query not sorting Properly (Excel 2013)

Copper Contributor

Hello all, I am new to these forums so forgive if I am doing anything wrong.

I have come across a problem with Power Query in Excel 2013.  I am importing from a Table in a different Excel workbook, I have removed some columns and i then want to sort the data by each of the four coulumns in turn.

 

Ihave never had an issue with this in the past and it was always quite simple, in fact in the query editor it appears to sort OK.

 

Yet when i select "Close and Load" when the table updates it is not sorted at all.  The columns to be sorted are text columns.

 

Any ideas what to look for?

9 Replies

Hi Peter,

 

That could be bit abstract without knowing the details of you model, however,

- on PQ site try to isolate your table in memory using 'Add this data to Data Model' in Load To options; or by using Table.Buffer() in M script;

- on Excel site right click on your table and in Table->External Data Properties be sure options are checked as you need, especially Preserve column sort/filter/layout

Hi Sergei,

 

Thanks a lot for your comments!
I have tha same issue of Peter. The sorting look correct in Query Editor Preview, however when I Load to table the sorting looks completely different

I noticed that sorting follows the ASCII codes, which is different from Excel's sorting behavior. Does it explain the unexpected sorting result?

@Peter Downer I know it's been a long time but I've been looking for an answer to this problem for a long time and found it on an even older thread: unchecking the "Add this to the Data Model" option in the "Load To..." settings, makes the data sorting in the table the same as the one seen in the query preview.

Source: https://chandoo.org/forum/threads/power-query-sorting.23455/

@claudiapeitzp 

To sort correctly you need to fox the table in memory. IMHO, Load to data model is not the optimal way for that.

I’m not sure what you mean by fixing the table in memory but I tried multiple solutions (sort by index, changing the data type, etc) and this was the only one that worked. Unlike for instance Pivot Tables, I also found no special benefits or changes by adding the data to the model so this solution didn’t really take away any “optimality” for me, on the contrary.

@claudiapeitzp 

You may fix in memory by using Table.Buffer(Table.Sort... or by adding Index column right before sorting and remove it after that if not needed.

Thank you! The issue was corrected.
Thank you, this resolved my sorting issue