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 without losing non-mutual entries in the Table-1.
(First Table in the image is Table-2 and second one with one column is Table-1).
There are some extra entries in table 1 which are not present on table two. I want to merge them by keeping non mutual entries entact and blank.
How to do so? Any suggestion/help would be appreciated.
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
Easier with Power Query or you are looking for formula solution?
- Shivam_RaiCopper ContributorThanks for your response. I would prefer Power Query, but I can try by any method possible.
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