+ Reply to Thread
Results 1 to 10 of 10

Power Query - how to keep order of the source table

  1. #1
    Forum Contributor
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    365
    Posts
    204

    Power Query - how to keep order of the source table

    Hi,

    I would like to have the same order of rows in PQ result table (spe\readsheet Baza) vs source table Sales_New (spreadsheet Sales_New). Is it possible to make it directly in PQ?

    pls find the file attached
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: Power Query - how to keep order of the source table

    you can add an index on the source data and sort it at the resulting table?
    I cannot check it because I cannot read a part of your queries and something is missing too

  3. #3
    Forum Contributor
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    365
    Posts
    204

    Re: Power Query - how to keep order of the source table

    hi,

    yes, I was thinking about that. but I would have to sort both tables each time by hand. If that was me, it would not be a problem, but this file will be used by few other guys and they might forget it. The source table might have different numbers of rows each week, so it is dynamic and sort will be done in different columns. So, this could be not perfect solution.

    I am looking for something automatic, to be done on a spot

    file attached once again, hope it will work now
    Attached Files Attached Files

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Power Query - how to keep order of the source table

    The SalesNew query should load in the same order as your source table, so you add the Index in PQ. You can then sort on that at the end.
    Rory

  5. #5
    Forum Contributor
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    365
    Posts
    204

    Re: Power Query - how to keep order of the source table

    hi,

    I know that Sales_New should have that column with numbers. however, this table will change and can be sorted by different people on diffrent columns (+ new rows will appear constantly) , so in the end it will not be sorted in sequence of "1, 2, 3, ..."

    Therefore, is there any possibility that the order of the final table is the same as Sales_New and does not matter what way was Sales_New sorted?

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Power Query - how to keep order of the source table

    Did you try it? If you add the index column in Power Query, the numbers will always be in the same order as the source table when the query is refreshed.

  7. #7
    Forum Contributor
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    365
    Posts
    204

    Re: Power Query - how to keep order of the source table

    yes, attached.

    However, the problem appears when Sales_New is not sorted in the first place, just before refresh. If it is sorted in a way of "1,2,3...", I have the required outcome (problem solved), but if it is randomly sorted, it does not go in the same order when refresh with PQ.

    The reason I need to do it, is because the results from the final table has to be copied in the same order as Sales_New to other table (which always will be in the same order as Sales_New). sorry, if it is to complicated

    P.S. I caanot use any VBA nor PQ in that last stage (that is copy/paste), because it will be done in different tables/files, etc.
    Attached Files Attached Files

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Power Query - how to keep order of the source table

    You've misunderstood. You do not add the index numbers to the SalesNew table. You add it in Power Query.

  9. #9
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Power Query - how to keep order of the source table

    Please try below M code

    the key is to use Table.Buffer() before Expanded Reordered Columns

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    365
    Posts
    204

    Re: Power Query - how to keep order of the source table

    looks promising let me check that for a day

    thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Power Query Refresh Order
    By Steveapa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-20-2019, 11:02 PM
  2. Replies: 2
    Last Post: 02-13-2019, 07:39 AM
  3. Power Query SQL (Source) run with manual table parameter?
    By Steveapa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2019, 09:03 PM
  4. Replies: 1
    Last Post: 11-12-2018, 02:46 PM
  5. Power Query: Using a Parameter to specify a source table name.
    By learning new things in forum Excel General
    Replies: 0
    Last Post: 11-06-2018, 04:21 PM
  6. Replies: 5
    Last Post: 06-29-2018, 05:35 AM
  7. Power Query Source vs Different PCs
    By flpneves in forum Excel General
    Replies: 1
    Last Post: 12-05-2017, 01:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1