Forum Discussion
Shivam_Rai
Sep 10, 2023Copper Contributor
NEED HELP REGARDING MERGING TWO TABLES INTO ONE
Hi! I need some help. I have two tables in excel, Table-1 with a list of 785 rank entries, and Table-2 with 433 rank entries with other associated data. I need to merge data of two tables into one w...
- Sep 10, 2023
If something like this
query both sources, rename in first ID=>ID1, second ID=>ID2 (rank in your case) and merge as new table with FullOuter option. Script is like
let Source = Table.NestedJoin( Table1, {"ID1"}, Table2, {"ID2"}, "Table2", JoinKind.FullOuter), names1 = List.RemoveLastN( Table.ColumnNames( Source ), 1), names2 = Table.ColumnNames( Source[Table2]{0} ), expandMerged = Table.ExpandTableColumn( Source, "Table2", names2, names2), addID = Table.AddColumn( expandMerged, "ID", each List.RemoveNulls( {[ID1]} & {[ID2]} ){0}, Int64.Type), keepColumns = Table.SelectColumns( addID, {"ID"} & List.Skip(names1) & List.Skip(names2) ), sortByID = Table.Sort(keepColumns,{{"ID", Order.Ascending}}) in sortByID
SergeiBaklan
Sep 10, 2023Diamond Contributor
Easier with Power Query or you are looking for formula solution?
- Shivam_RaiSep 10, 2023Copper ContributorThanks for your response. I would prefer Power Query, but I can try by any method possible.
- SergeiBaklanSep 10, 2023Diamond Contributor
If something like this
query both sources, rename in first ID=>ID1, second ID=>ID2 (rank in your case) and merge as new table with FullOuter option. Script is like
let Source = Table.NestedJoin( Table1, {"ID1"}, Table2, {"ID2"}, "Table2", JoinKind.FullOuter), names1 = List.RemoveLastN( Table.ColumnNames( Source ), 1), names2 = Table.ColumnNames( Source[Table2]{0} ), expandMerged = Table.ExpandTableColumn( Source, "Table2", names2, names2), addID = Table.AddColumn( expandMerged, "ID", each List.RemoveNulls( {[ID1]} & {[ID2]} ){0}, Int64.Type), keepColumns = Table.SelectColumns( addID, {"ID"} & List.Skip(names1) & List.Skip(names2) ), sortByID = Table.Sort(keepColumns,{{"ID", Order.Ascending}}) in sortByID