Home

Sorting table in Power Query produces different results to sorting same table in Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-1274066%22%20slang%3D%22en-US%22%3ESorting%20table%20in%20Power%20Query%20produces%20different%20results%20to%20sorting%20same%20table%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1274066%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20power%20query%20table%20that%20includes%20as%20it's%20last%20step%20a%20sort%20of%20rows%20based%20on%204%20fields%203%20of%20which%20are%20numeric%20data%20type.%20The%20query%20loads%20the%20table%20back%20into%20a%20worksheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20worksheet%20i%20have%20added%20some%20columns%20that%20test%20values%20in%20the%20current%20row%20to%20the%20previous%20row%20in%20order%20to%20set%20an%20Id%20field%20which%20is%20why%20it%20is%20critical%20that%20the%20table%20is%20sorted%20correctly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20noticed%20that%20the%20results%20reflected%20in%20correct%20sorting%20so%20I%20then%20set%20sort%20parameters%20on%20the%20table%20in%20the%20worksheet%20which%20produced%20the%20correct%20results%20(by%20way%20of%20sorting%20the%20rows).%20but%20Excel%20asked%20me%20to%20accept%20treating%20looks%20like%20a%20number%20as%20numeric.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20noticed%20is%20that%20the%20tables%20loaded%20from%20the%20query%20has%20all%20the%20numeric%20columns%20(per%20the%20query%20data%20type)%20showing%20as%20type%20%22General%22.%20If%20I%20change%20the%20columns%20that%20are%20numeric%20to%20%22Number%22%20I%20end%20up%20with%20the%20same%20results%20as%20per%20the%20power%20query%20by%20way%20of%20incorrectly%20sorting%20the%20rows.%20I%20have%20checked%206%20specific%20records%20that%20show%20problem%20and%20cn%20find%20nothing%20strange%20in%20their%20content.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhy%20do%20I%20get%20such%20huge%20difference%20between%20the%20query%20sorted%20rows%20result%20and%20the%20excel%20table%20sort%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanking%20you...%20Greg%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1274066%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1274359%22%20slang%3D%22en-US%22%3ERe%3A%20Sorting%20table%20in%20Power%20Query%20produces%20different%20results%20to%20sorting%20same%20table%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1274359%22%20slang%3D%22en-US%22%3EAny%20chance%20on%20getting%20a%20file%20with%20sample%20data%3F%20I%20suspect%20there%20is%20a%20problem%20with%20how%20the%20data%20is%20interpreted%20in%20PQ%20with%20regards%20to%20the%20data%20type.%20You%20MUST%20make%20sure%20the%20data%20type%20in%20PQ%20is%20correct%2C%20otherwise%20the%20data%20type%20of%20the%20end%20result%20as%20it%20is%20placed%20in%20Excel%20may%20be%20very%20different%20from%20PQ%20and%20from%20what%20you%20intend.%20Needless%20to%20say%20if%20a%20column%20has%20data%20type%20A%20in%20PQ%20and%20datatype%20B%20in%20Excel%2C%20sort%20is%20different.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1277068%22%20slang%3D%22en-US%22%3ERe%3A%20Sorting%20table%20in%20Power%20Query%20produces%20different%20results%20to%20sorting%20same%20table%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1277068%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20reply%20and%20I%20have%20already%20checked%20that.%20The%20file%20in%20question%20is%20rather%20large%20but%20I%20will%20attempt%20to%20replicate%20the%20situation%20with%20a%20much%20smaller%20sample%20to%20illustrate%20my%20situation.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I have a power query table that includes as it's last step a sort of rows based on 4 fields 3 of which are numeric data type. The query loads the table back into a worksheet.

 

In the worksheet i have added some columns that test values in the current row to the previous row in order to set an Id field which is why it is critical that the table is sorted correctly.

 

I noticed that the results reflected in correct sorting so I then set sort parameters on the table in the worksheet which produced the correct results (by way of sorting the rows). but Excel asked me to accept treating looks like a number as numeric.

 

What I noticed is that the tables loaded from the query has all the numeric columns (per the query data type) showing as type "General". If I change the columns that are numeric to "Number" I end up with the same results as per the power query by way of incorrectly sorting the rows. I have checked 6 specific records that show problem and cn find nothing strange in their content.

 

Why do I get such huge difference between the query sorted rows result and the excel table sort?

 

Thanking you... Greg

2 Replies
Highlighted
Any chance on getting a file with sample data? I suspect there is a problem with how the data is interpreted in PQ with regards to the data type. You MUST make sure the data type in PQ is correct, otherwise the data type of the end result as it is placed in Excel may be very different from PQ and from what you intend. Needless to say if a column has data type A in PQ and datatype B in Excel, sort is different.
Highlighted

@Jan Karel Pieterse 

 

Thanks for your reply and I have already checked that. The file in question is rather large but I will attempt to replicate the situation with a much smaller sample to illustrate my situation.