+ Reply to Thread
Results 1 to 9 of 9

Power Query Grouping undos sort

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Power Query Grouping undos sort

    I have a table listing providers (Table "Cities") and the cities they serve. If a provider is in multiple cities, they would be listed each time but on a separate row.

    2nd table (Table "Providers") isolates and displays only unduplicated providers.

    I am attempting to produce a table of unduplicated providers with 1 merged column of all the cities they serve. Cities should be separated by a delimiter (comma) and displayed alphabetically.

    Steps followed in Power Query:
    "Cities" Table
    1. Sort by Provider Name and then City name.
    2. Group rows
    3. Added Custom column to isolate distinct rows by delimiter.
    4. Extract values of list
    At this point the Cities are displayed correctly with delimiter and in alphabetic order.

    As soon as I merge "Provider" query to "Cities" query, the contents of the "Cities" column are no longer in alphabetic order. I'm not sure why this is happening.......frustrated!
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Power Query Grouping undos sort

    A formula alternative:

    =LET(P,Providers[Provider Name],VSTACK(Cities[#Headers],HSTACK(P,BYROW(P,LAMBDA(x,IFERROR(TEXTJOIN(", ",,SORT(FILTER(Cities[City],Cities[Provider Name]=x))),""))))))
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Re: Power Query Grouping undos sort

    Thanks Glenn. Can this be down inside power query?

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Power Query Grouping undos sort

    I'm sure it can... but I have no idea how to make it do so. I don't like PQ... it doesn't auto-update etc. I just offered an alternative.

  5. #5
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Query Grouping undos sort

    do you want something like this?

    Provider Name Cities
    A.W. HOLDINGS, LLC
    ABC Healthcare of America, LLC Atlanta, Columbus, Decatur, Snellville, West Snellville
    Abagails Personal Care Home Agency Inc. Locust Grover
    Building Bridges Therapy
    Comfort Care Columbus
    GCSS Blairsville, Ellenwood, Hinesville
    HIHOPE SERVICE CENTER INC
    JIMMYS MAGNOLIA TREE INC
    Williams Personal Care Home Decatur, Griffin, Snellville, Stone Mountain

  6. #6
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Re: Power Query Grouping undos sort

    Yes Sandy!

  7. #7
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Query Grouping undos sort

    so use this

    // Providers
    let
        Source = Excel.CurrentWorkbook(){[Name="Providers"]}[Content]
    in
        Source
    // Cities
    let
        Source = Excel.CurrentWorkbook(){[Name="Cities"]}[Content]
    in
        Source
    // Join
    let
        Join = Table.NestedJoin(Providers, {"Provider Name"}, Cities, {"Provider Name"}, "Cities", JoinKind.LeftOuter),
        Exp = Table.ExpandTableColumn(Join, "Cities", {"City"}, {"City"}),
        Grp = Table.Group(Exp, {"Provider Name"}, {{"Count", each _, type table}}),
        SortA = Table.Sort(Grp,{{"Provider Name", Order.Ascending}}),
        List = Table.AddColumn(SortA, "Cities", each List.Sort(List.Distinct([Count][City]), Order.Ascending)),
        Ext = Table.TransformColumns(List, {"Cities", each Text.Combine(List.Transform(_, Text.From), ", "), type text})
    in
        Ext
    btw. Power Query is NOT vba so this is wrong subforum

  8. #8
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Re: Power Query Grouping undos sort

    that worked!

  9. #9
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Query Grouping undos sort

    Quote Originally Posted by KerahJoy View Post
    that worked!
    I know

    mark the thread as SOLVED (top above your first post - Thread Tools)

+ 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. Grouping Power Query Column
    By nick3516 in forum Excel General
    Replies: 5
    Last Post: 11-06-2022, 01:30 PM
  2. [SOLVED] Excel Power Query Grouping list
    By Dicken in forum Office 365
    Replies: 9
    Last Post: 08-15-2022, 08:21 AM
  3. Replies: 2
    Last Post: 11-12-2021, 03:44 AM
  4. Power query grouping - conditional to data across several columns??...
    By sunnyspirit in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-01-2021, 11:53 AM
  5. Data grouping in Power Query
    By hudson andrew in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2020, 10:44 AM
  6. [SOLVED] Get and Transform (Power Query) - Grouping numbers into bands/buckets
    By TheNewUnion in forum Excel General
    Replies: 2
    Last Post: 03-12-2019, 05:37 AM
  7. Help with grouping in power query
    By stephme55 in forum Excel General
    Replies: 1
    Last Post: 07-26-2016, 03:09 PM

Tags for this Thread

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