Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Conditional data source join

Hi All,

 

I have 2 data sources and in both of them thare are columns NAME and ID. I would like to do a conditional join such as:

If NAME and ID are equal in both data sources join it based on these 2 columns; if not join it only based on NAME column.

 

If anybody can provide code from advance editor I would be very greatful.

 

Thanks

  • Anonymous 

    Try following code.

    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Id", "Name"}, Table2, {"ID", "Name"}, "Table2", JoinKind.LeftOuter),
    #"Merged Queries1" = Table.NestedJoin(#"Merged Queries", {"Name"}, Table2, {"Name"}, "Table2.1", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries1", "Custom", each if Table.RowCount([Table2]) > 0 then [Table2] else [Table2.1])
    in
    #"Added Custom"

     

     

1 Reply

  • AUDISU's avatar
    AUDISU
    Resolver III

    Anonymous 

    Try following code.

    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Id", "Name"}, Table2, {"ID", "Name"}, "Table2", JoinKind.LeftOuter),
    #"Merged Queries1" = Table.NestedJoin(#"Merged Queries", {"Name"}, Table2, {"Name"}, "Table2.1", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries1", "Custom", each if Table.RowCount([Table2]) > 0 then [Table2] else [Table2.1])
    in
    #"Added Custom"