Forum Discussion

moizsherwani's avatar
moizsherwani
Continued Contributor
7 years ago
Solved

Joining Two Tables With Partial Matching Values

Hello everyone,   So diving into my problem right away, I need to join two tables with partially matching values, the example should explain it. I was hoping there could be some kind of Merge at th...
  • LivioLanzo's avatar
    7 years ago

    Hi moizsherwani

     

    this should be a simple full outer join with a custom column added at the end:

     

    let
        Source = Table.NestedJoin(Table1,{"Col. A", "Col. B"},Table2,{"Col. A", "Col. B"},"Table2",JoinKind.FullOuter),
        #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Col. A", "Col. B"}, {"Table2.Col. A", "Table2.Col. B"}),
        #"Added Custom" = Table.AddColumn(#"Expanded Table2", "id", each if [Col. A] = null then [Table2.Col. A] else [Col. A], Int64.Type),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"id", "Col. B", "Table2.Col. B"})
    in
        #"Removed Other Columns"