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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
BeAStar
Frequent Visitor

Combine rows from multiple sources into single row adding a column identifying source

I have multiple text files that I have combined into one table, some of the files contain the same record and I want to combine the duplicated rows into one and  have a new column that shows the concatenation of one of the fields from the text files.

 

Example: 2 text files, File1 and File2; File1 has columns A (unique ID), B, D and E which has value "Conference X"; File2 file has A (unique ID), B, C and E which has value "Conference Y"; I need to combine the files and for rows in File1 and File2 where Column A has the same value I want to have one row (Column A) and columns B,C and D, but need a new column F that concatenates the values from Column E from the different files where column A is the same

bdecorral_0-1645373489253.png

Appreciate the help!! Thank you!!

2 ACCEPTED SOLUTIONS
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @BeAStar ,

 

Here is my solution:

tomfox_2-1645377174115.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough) Note my tables have the prefix Table27_.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k3NTUot8nRR0lEyNDQEkkZGRkDSOT8vLbUoNS85VSFCKVYHTZ0RWJ0xQXXGYHUmBNWZgNWZYqiLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t, #"Column B" = _t, #"Column D" = _t, #"Column E" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column A", type text}, {"Column B", Int64.Type}, {"Column D", Int64.Type}, {"Column E", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Column A", "Column B"}, Table27_File2, {"Column A", "Column B"}, "Table27_File2", JoinKind.FullOuter),
#"Expanded Table27_File2" = Table.ExpandTableColumn(#"Merged Queries", "Table27_File2", {"Column A", "Column B", "Column C", "Column E"}, {"Table27_File2.Column A", "Table27_File2.Column B", "Table27_File2.Column C", "Table27_File2.Column E"}),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Table27_File2",null,each [Table27_File2.Column A],Replacer.ReplaceValue,{"Column A"}),
#"Replaced Value 2" = Table.ReplaceValue(#"Replaced Value",null,each [Table27_File2.Column B],Replacer.ReplaceValue,{"Column B"}),
#"Added Custom" = Table.AddColumn(#"Replaced Value 2", "Column F", each if [Column E] = null and [Table27_File2.Column E] <> null then [Table27_File2.Column E] else if [Column E] <> null and [Table27_File2.Column E] = null then [Column E] else [Column E] & ";" &[Table27_File2.Column E]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Column E", "Table27_File2.Column A", "Table27_File2.Column B", "Table27_File2.Column E"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Table27_File2.Column C", "Column C"}})
in
#"Renamed Columns"

 

Hope this helps! 🙂 

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

This is AMAZING!!!! Thanks Tom!!!!

View solution in original post

2 REPLIES 2
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @BeAStar ,

 

Here is my solution:

tomfox_2-1645377174115.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough) Note my tables have the prefix Table27_.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k3NTUot8nRR0lEyNDQEkkZGRkDSOT8vLbUoNS85VSFCKVYHTZ0RWJ0xQXXGYHUmBNWZgNWZYqiLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t, #"Column B" = _t, #"Column D" = _t, #"Column E" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column A", type text}, {"Column B", Int64.Type}, {"Column D", Int64.Type}, {"Column E", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Column A", "Column B"}, Table27_File2, {"Column A", "Column B"}, "Table27_File2", JoinKind.FullOuter),
#"Expanded Table27_File2" = Table.ExpandTableColumn(#"Merged Queries", "Table27_File2", {"Column A", "Column B", "Column C", "Column E"}, {"Table27_File2.Column A", "Table27_File2.Column B", "Table27_File2.Column C", "Table27_File2.Column E"}),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Table27_File2",null,each [Table27_File2.Column A],Replacer.ReplaceValue,{"Column A"}),
#"Replaced Value 2" = Table.ReplaceValue(#"Replaced Value",null,each [Table27_File2.Column B],Replacer.ReplaceValue,{"Column B"}),
#"Added Custom" = Table.AddColumn(#"Replaced Value 2", "Column F", each if [Column E] = null and [Table27_File2.Column E] <> null then [Table27_File2.Column E] else if [Column E] <> null and [Table27_File2.Column E] = null then [Column E] else [Column E] & ";" &[Table27_File2.Column E]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Column E", "Table27_File2.Column A", "Table27_File2.Column B", "Table27_File2.Column E"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Table27_File2.Column C", "Column C"}})
in
#"Renamed Columns"

 

Hope this helps! 🙂 

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

This is AMAZING!!!! Thanks Tom!!!!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.