Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How can I convert/pivot repeating rows in the same column into individual columns for a single line?

I need assistance converting the following table:

 

NameDirectory ContactDirectory Contact TitleDirectory Contact EmailDirectory Contact Phone
AcmeElmer FuddLead Hunter[email protected]555-555-5555
AcmeBugs BunnyDirector of Carrot Intake[email protected]444-444-4444
AcmeWile E. CoyoteDirector of Traps[email protected]333-333-3333
DisneyMickey MouseActor[email protected]111-111-1111
DisneyGoofy DogClown[email protected]222-222-2222

 

I want the final result to look like this:

 

Company NameDirectory Contact 1Directory Contact Title 1Directory Contact Email Address 1Directory Contact Phone 1Directory Contact 2Directory Contact Title 2Directory Contact Email Address 2Directory Contact Phone 2Directory Contact 3Directory Contact Title 3Directory Contact Email Address 3Directory Contact Phone 3
AcmeElmer FuddLead Hunter[email protected]555-555-5555Bugs BunnyDirector of Carrot Intake[email protected]444-444-4444Wile E. CoyoteDirector of Traps[email protected]333-333-3333
DisneyMickey MouseActor[email protected]111-111-1111Goofy DogClown[email protected]222-222-2222    
  • Anonymous 

     

    Refer to this post which does exactly what you need.

     

    https://excelgorilla.com/power-bi/power-query/aggregate-text-values-using-group-by/

     

    After you modify the group by M query, the table will look like below and use Split column with delimiter option to split each values into individual columns.

     

    Here is the M query for group by ..

        #"Grouped Rows" = Table.Group(#"Changed Type", {"Name"}, {{"Directory Contact", each Text.Combine([Directory Contact],","), type text}, {"Directory Contact Title", each Text.Combine([Directory Contact Title],","), type text}, {"Directory Contact Email", each Text.Combine([Directory Contact Email],","), type text}, {"Directory Contact Phone", each Text.Combine([Directory Contact Phone],","), type text}})

     

     

    If it helps, mark it as a solution

    Kudos are nice too

     

     

3 Replies

  • VasTg's avatar
    VasTg
    Memorable Member

    Anonymous 

     

    Refer to this post which does exactly what you need.

     

    https://excelgorilla.com/power-bi/power-query/aggregate-text-values-using-group-by/

     

    After you modify the group by M query, the table will look like below and use Split column with delimiter option to split each values into individual columns.

     

    Here is the M query for group by ..

        #"Grouped Rows" = Table.Group(#"Changed Type", {"Name"}, {{"Directory Contact", each Text.Combine([Directory Contact],","), type text}, {"Directory Contact Title", each Text.Combine([Directory Contact Title],","), type text}, {"Directory Contact Email", each Text.Combine([Directory Contact Email],","), type text}, {"Directory Contact Phone", each Text.Combine([Directory Contact Phone],","), type text}})

     

     

    If it helps, mark it as a solution

    Kudos are nice too

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      VasTg, this is great and will be marked as the solution. Out of curiosity, is there any way to accomplish this via the UI for users who are less code-inclined?

      • VasTg's avatar
        VasTg
        Memorable Member

        Anonymous 

         

        This definetely need a GROUP BY and I don't see the option there.