cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Newuser13
Helper I
Helper I

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

1 ACCEPTED SOLUTION
AUDISU
Resolver II
Resolver II

@Newuser13 

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"

 

AUDISU_0-1664278453550.png

 

View solution in original post

1 REPLY 1
AUDISU
Resolver II
Resolver II

@Newuser13 

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"

 

AUDISU_0-1664278453550.png

 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors