Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ryan_b_123
Frequent Visitor

Merge two tables as a list

I would like to join Table 2 (Team ID) onto Table 1 (Team ID) and add a list of names retrieved from the join (rather than a row for each match).  Appreciate the help!

 

Table 1

Shipment IDTeam ID
1A
2B
3C
4A

 

Table 2

NameTeam ID
BillyA
JohnA
LisaB
CarlosC
MichelleC
TitoC

 

End Result

Shipment IDTeam IDNames
1A[Billy, John]
2B[Lisa]
3C[Carlos, Michelle, Tito]
4A[Billy, John]
1 ACCEPTED SOLUTION
rohit_singh
Solution Sage
Solution Sage

HI @ryan_b_123 ,

Please try this in Power Query :

1) Modify Table 2 as shown below. Perform a Group by operation on Team ID and then concatenate names into a single row. 

rohit_singh_0-1654161968493.png

rohit_singh_1-1654161983295.png

Table 2 : 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMyalU0lFyVIrViVbyys/Ig3N8MosTgRwnMMc5sSgnvxjIdQZzfTOTM1JzclLhAiGZJfkQTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Team ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Team ID", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Team ID"}, {{"Count", each _, type table [Name=nullable text, Team ID=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [Count][Name]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), " , "), type text}),
    #"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Count"})
in
    #"Removed Columns"

 

 

2) Navigate to Table 1. Merge Table 1 and 2 using Team ID.

rohit_singh_2-1654162135782.png

3) Expand Table 2 from the join. You need to extract only the list of names (column "Custom")

rohit_singh_3-1654162229623.png

4) This will give you the final result 

rohit_singh_4-1654162418708.png

Table 1 :

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWJVjICspzALGMgyxnMMoHIxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Shipment ID" = _t, #"Team ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Shipment ID", Int64.Type}, {"Team ID", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Team ID"}, Names, {"Team ID"}, "Names", JoinKind.LeftOuter),
    #"Expanded Names" = Table.ExpandTableColumn(#"Merged Queries", "Names", {"Custom"}, {"Custom"})
in
    #"Expanded Names"

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

View solution in original post

2 REPLIES 2
rohit_singh
Solution Sage
Solution Sage

HI @ryan_b_123 ,

Please try this in Power Query :

1) Modify Table 2 as shown below. Perform a Group by operation on Team ID and then concatenate names into a single row. 

rohit_singh_0-1654161968493.png

rohit_singh_1-1654161983295.png

Table 2 : 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMyalU0lFyVIrViVbyys/Ig3N8MosTgRwnMMc5sSgnvxjIdQZzfTOTM1JzclLhAiGZJfkQTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Team ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Team ID", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Team ID"}, {{"Count", each _, type table [Name=nullable text, Team ID=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [Count][Name]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), " , "), type text}),
    #"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Count"})
in
    #"Removed Columns"

 

 

2) Navigate to Table 1. Merge Table 1 and 2 using Team ID.

rohit_singh_2-1654162135782.png

3) Expand Table 2 from the join. You need to extract only the list of names (column "Custom")

rohit_singh_3-1654162229623.png

4) This will give you the final result 

rohit_singh_4-1654162418708.png

Table 1 :

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWJVjICspzALGMgyxnMMoHIxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Shipment ID" = _t, #"Team ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Shipment ID", Int64.Type}, {"Team ID", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Team ID"}, Names, {"Team ID"}, "Names", JoinKind.LeftOuter),
    #"Expanded Names" = Table.ExpandTableColumn(#"Merged Queries", "Names", {"Custom"}, {"Custom"})
in
    #"Expanded Names"

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

@ryan_b_123 @rohit_singh 

 

This can be done in a single step if you modify the Group By aggregation to use Text.Combine.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMyalU0lFyVIrViVbyys/Ig3N8MosTgRwnMMc5sSgnvxjIdQZzfTOTM1JzclLhAiGZJfkQTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Team ID" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Team ID"}, {{"Names", each Text.Combine([Name], ", "), type nullable text}})
in
    #"Grouped Rows"

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors