Reply
AtticusZak
New Member
Partially syndicated - Outbound

Merge multiple lines of data into one while extending data into row while merging

Good Morning,

I have an issue where I need some help. I have a list of data where I have a unique ID number for each customer. On that customer i have multiple rows of who is assigned to the account. I need to merge the multilple rows (2-5 each) into the same row using the Customer ID for reference and in theory the rest of the data to tack on at the end of the line where the previous row left off that it was merged to. 

 

AtticusZak_1-1660916411815.png

 

For this example each Account ID has 2 team members associated. 

I would like to to read exactly how line 1 is shown but then add the information from line 2 as the Account Id matches and add the remainder of the row to the tail end (Cell E1-G1) 

 

 

1 ACCEPTED SOLUTION

Syndicated - Outbound

Hi @AtticusZak - to achieve your outcome you need to understand the advanced feature of Table.Group.  Please consider the following Advanced Group By Tricks in Power Query - YouTube.  Chandeep gives good explanation.  Using this approach, you will have a table with the following:

 

DarylLynchBzy_0-1660932379719.png

 

Within the Nested Table in each row, you will find the two Rows with the employee details that you want to split in Column groups.  To these tables though we want to add an Table.AddIndexColumn.

DarylLynchBzy_1-1660932829453.png

We can now expand the table columns to add Employer, Job, Email, Phone and Index back to Customer.

DarylLynchBzy_2-1660932934156.png

We can now use the Unpivot and Pivot features in Power Query to transition the Columns to Rows then to separate Columns.  Transpose, pivot or unpivot in Power Query? - YouTube

DarylLynchBzy_3-1660933033428.png

 

DarylLynchBzy_4-1660933118403.png

 

Here is the code I created:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspPKlbSUfLKTwWSvolF2aklmXnpQLYjEBsqxeoglCTmAcngxJxUEM8JiI3A0kGJyRmpOcVQ7UDKvwDEcQZiYwwFeSmVSIa4ALGJUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Employee = _t, Job = _t, Email = _t, Phone = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Customer"}, {{"Table", each Table.AddIndexColumn(_ , "Index" , 1, 1) }}),
    #"Expanded Table" = Table.ExpandTableColumn(#"Grouped Rows", "Table", {"Employee", "Job", "Email", "Phone", "Index"}, {"Employee", "Job", "Email", "Phone", "Index"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Expanded Table", {"Customer", "Index"}, "Attribute", "Value"),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Columns", {{"Index", type text}}, "en-GB"),{"Attribute", "Index"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Pivoted Column",{{"Employee 1", type text}, {"Job 1", type text}, {"Email 1", type text}, {"Phone 1", type text}, {"Employee 2", type text}, {"Job 2", type text}, {"Email 2", type text}, {"Phone 2", type text}})
in
    #"Changed Type"




 

 

View solution in original post

3 REPLIES 3
AtticusZak
New Member

Syndicated - Outbound

Hello Daryl. 

Im looking to do something like this shown below but on a much larger scale. 

 

AtticusZak_0-1660929665706.png

Turned into 

AtticusZak_1-1660929868790.png

Customer being the place holder and all other rows for the same company merged/added onto the Customer line

Syndicated - Outbound

Hi @AtticusZak - to achieve your outcome you need to understand the advanced feature of Table.Group.  Please consider the following Advanced Group By Tricks in Power Query - YouTube.  Chandeep gives good explanation.  Using this approach, you will have a table with the following:

 

DarylLynchBzy_0-1660932379719.png

 

Within the Nested Table in each row, you will find the two Rows with the employee details that you want to split in Column groups.  To these tables though we want to add an Table.AddIndexColumn.

DarylLynchBzy_1-1660932829453.png

We can now expand the table columns to add Employer, Job, Email, Phone and Index back to Customer.

DarylLynchBzy_2-1660932934156.png

We can now use the Unpivot and Pivot features in Power Query to transition the Columns to Rows then to separate Columns.  Transpose, pivot or unpivot in Power Query? - YouTube

DarylLynchBzy_3-1660933033428.png

 

DarylLynchBzy_4-1660933118403.png

 

Here is the code I created:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspPKlbSUfLKTwWSvolF2aklmXnpQLYjEBsqxeoglCTmAcngxJxUEM8JiI3A0kGJyRmpOcVQ7UDKvwDEcQZiYwwFeSmVSIa4ALGJUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Employee = _t, Job = _t, Email = _t, Phone = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Customer"}, {{"Table", each Table.AddIndexColumn(_ , "Index" , 1, 1) }}),
    #"Expanded Table" = Table.ExpandTableColumn(#"Grouped Rows", "Table", {"Employee", "Job", "Email", "Phone", "Index"}, {"Employee", "Job", "Email", "Phone", "Index"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Expanded Table", {"Customer", "Index"}, "Attribute", "Value"),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Columns", {{"Index", type text}}, "en-GB"),{"Attribute", "Index"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Pivoted Column",{{"Employee 1", type text}, {"Job 1", type text}, {"Email 1", type text}, {"Phone 1", type text}, {"Employee 2", type text}, {"Job 2", type text}, {"Email 2", type text}, {"Phone 2", type text}})
in
    #"Changed Type"




 

 

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Syndicated - Outbound

Hi @AtticusZak - a couple of suggestion that might help the community help you. 
(1) Could you add some sample data using the "Add Data" feature in Power BI?
(2) Could you show an example of what you think the end result might look like using Excel?
Many Thanks

Daryl

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)