Forum Discussion

EaglesTony's avatar
EaglesTony
Icon for Post Prodigy rankPost Prodigy
1 year ago
Solved

How can I collapse multiple rows to single with last row as concatenated

Hi,     I have the following data that is grouped:   Area        Domain      Sub-Domain      TeamMember A             B                 C                        John A             B            ...
  • MasonMA's avatar
    1 year ago

    Hi EaglesTony 

     

    I'd recommend leveraging UI as much as you can and only coding wherever not possible with UI. For this You can use UI to Group by first 3 Columns and have UI generate the M code, then with some modification on the code to concatenate the Names. 

     

     

    The UI will generate M code below

    = Table.Group(Source, {"Area", "Domain", "Sub-Domain"}, {{"teamMembers", each _, type table [Area=text, Domain=text, #"Sub-Domain"=text, TeamMember=text]}})

     

    then Replace the part

    {{"teamMembers", each _, type table [Area=text, Domain=text, #"Sub-Domain"=text, TeamMember=text]}}

    with below M code to concatenate those names. 

    {{"TeamMembers", each Text.Combine([TeamMember], " / "), type text}}

     

    Hope this helps:)