Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
rlpa1295
New Member

How to do merge join with two conditional fields?

Hi, this is my question. I try to do a merge join with two tables that don't have just one field in common. Both tables have two fields in commom (the date and the ID User). But one of them has a date that I want to take in just one table. So I have problems to do the merge join because I have two fields and Power BI just allow me to do Merge with one field in common. In fact, I was wondering if I can do this SQL Query in Power BI.

 

Select * from table A inner join table B on (A.ID_User=B.Id_User AND A.DateReg=B.DateReg)

 

Thanks for your time

 

Rolando

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee


@rlpa1295 wrote:

Hi, this is my question. I try to do a merge join with two tables that don't have just one field in common. Both tables have two fields in commom (the date and the ID User). But one of them has a date that I want to take in just one table. So I have problems to do the merge join because I have two fields and Power BI just allow me to do Merge with one field in common. In fact, I was wondering if I can do this SQL Query in Power BI.

 

Select * from table A inner join table B on (A.ID_User=B.Id_User AND A.DateReg=B.DateReg)


 

You can surely do that inner join in Power BI. Just press shift and check more columns. See the small sequence numbers 1,2 in the snapshot.

 

Capture.PNG

 

TableB

let
    Source = Table.FromRows({{"user1", "2016-01-01"}, 
{"user5","2016-01-01"},
{"user3", "2016-01-07"}, 
{"user6", "2016-07-01"}},
{"ID_User","DateReg" } 
),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateReg", type date}})

in 
	#"Changed Type"

TableA

 

let
    Source = Table.FromRows({{"user1", "2016-01-01"}, 
{"user2","2016-01-01"},
{"user3", "2016-01-07"}, 
{"user4", "2016-07-01"}},
{"ID_User","DateReg" } 
),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateReg", type date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"ID_User", "DateReg"},TableB,{"ID_User", "DateReg"},"NewColumn",JoinKind.Inner),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"ID_User", "DateReg"}, {"NewColumn.ID_User", "NewColumn.DateReg"})

in 
	#"Expanded NewColumn"

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee


@rlpa1295 wrote:

Hi, this is my question. I try to do a merge join with two tables that don't have just one field in common. Both tables have two fields in commom (the date and the ID User). But one of them has a date that I want to take in just one table. So I have problems to do the merge join because I have two fields and Power BI just allow me to do Merge with one field in common. In fact, I was wondering if I can do this SQL Query in Power BI.

 

Select * from table A inner join table B on (A.ID_User=B.Id_User AND A.DateReg=B.DateReg)


 

You can surely do that inner join in Power BI. Just press shift and check more columns. See the small sequence numbers 1,2 in the snapshot.

 

Capture.PNG

 

TableB

let
    Source = Table.FromRows({{"user1", "2016-01-01"}, 
{"user5","2016-01-01"},
{"user3", "2016-01-07"}, 
{"user6", "2016-07-01"}},
{"ID_User","DateReg" } 
),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateReg", type date}})

in 
	#"Changed Type"

TableA

 

let
    Source = Table.FromRows({{"user1", "2016-01-01"}, 
{"user2","2016-01-01"},
{"user3", "2016-01-07"}, 
{"user4", "2016-07-01"}},
{"ID_User","DateReg" } 
),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateReg", type date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"ID_User", "DateReg"},TableB,{"ID_User", "DateReg"},"NewColumn",JoinKind.Inner),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"ID_User", "DateReg"}, {"NewColumn.ID_User", "NewColumn.DateReg"})

in 
	#"Expanded NewColumn"
Anonymous
Not applicable

Hi @Eric_Zhang 
   Am also facing this type of problem. but i have million records. when i try to this way it take huge time only. can we implement to dax side?.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.