Power Query Sort vs. Excel Sort

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have a column containing numbers and text together that I want to sort in Power Query. I want the sort to mimic the sort order that Excel would use if I sorted and chose "Sort numbers and numbers stored as text separately."

For example, I have the following values
Value
#750
#770
#8
#9
000.000.01001
000.000.01003
000.000.01004
000.000.01005
000-001
000-0030
000-0049-00
001

<tbody>
</tbody><colgroup><col></colgroup>


Note that the 001 at the bottom is a text value, not number.

When sorted in Excel, the list sorts as shown above. But if I load this table to PQ, sort, and load back to the worksheet, I get this
Value
#750
#770
#8
#9
000-001
000-0030
000-0049-00
000.000.01001
000.000.01003
000.000.01004
000.000.01005
001

<tbody>
</tbody><colgroup><col></colgroup>


The records in red have moved from the PQ sort.

I need the sort to be consistent with Excel's sort so I can use a MATCH formula with the sort criteria as being '1.'
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I guess you could duplicate the column in PQ, do some type conversions to sort the numbers from the text, and then go from there.

I need the sort to be consistent with Excel's sort so I can use a MATCH formula with the sort criteria as being '1.'

Maybe there is another way. I do t understand what you are saying above. What are you trying to do with match? Can you do it in PQ instead?
 
Upvote 0
The PQ table gets loaded back to an Excel worksheet, and I am doing lookups to that table in various worksheets with INDEX-MATCH. Since the table is rather large (about 750k rows), I find that the only way to make the lookup work well is by sorting it and using MATCH where the match type is 1.

The main reason I can't do it all in PQ is that the lookups need to be in various places throughout the workbook and just wouldn't be feasible to load them all into PQ.

What I do that works but adds an extra step is sorting the table after it gets loaded back to the worksheet, so that the sort is done by Excel instead of PQ.
 
Upvote 0
It sounds like there are 2 things then. One is the need to have the tables spread throughout the workbook, and the other is the need to do the lookups. But these things can be handled separately. You can load data into power query and not load those tables back to Excel, but just use them in Power Query to do the matching prior to loading this one table.
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,128
Members
448,947
Latest member
test111

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top