Forum Discussion
How to join a table with a subquery using power query M
- 7 years ago
I don't see why not, it's M code, you can pretty much do whatever you want. See my technique here:
https://social.technet.microsoft.com/wiki/contents/articles/32915.power-bi-merge-query-with-m.aspx
- 7 years ago
Well, if you don't want to write M code to keep it all in one query, you could simply create a new reference query to Table1. Right click Table1 query and choose "Reference". Then in that query right-click the EmpID column and choose to remove duplicates. Then just use that table in your merge query. Or you could just write those steps in M and keep it all in a single query without creating the table, but however you want to do it. For example something like this would probably work:
= Table.NestedJoin(Table.Distinct(Table1,{"EmpID"}),{"EmpID"},Table2,{"EmpID"},"Table2",JoinKind.LeftOuter)
Hi Greg_Deckler
Thank you for your help.
I know it is possible, I just don't know how to include the Distinct part in the query.
This is the query I use now to join the tables:
= Table.NestedJoin(Table1,{"EmpID"},Table2,{"EmpID"},"Table2",JoinKind.LeftOuter)
How would you modify the query to include only Distinct EmpID from Table1?
Well, if you don't want to write M code to keep it all in one query, you could simply create a new reference query to Table1. Right click Table1 query and choose "Reference". Then in that query right-click the EmpID column and choose to remove duplicates. Then just use that table in your merge query. Or you could just write those steps in M and keep it all in a single query without creating the table, but however you want to do it. For example something like this would probably work:
= Table.NestedJoin(Table.Distinct(Table1,{"EmpID"}),{"EmpID"},Table2,{"EmpID"},"Table2",JoinKind.LeftOuter)- kazael7 years agoHelper I
Hi Greg_Deckler,
It doesn't really work so I'll try to write the full M code using the article you attached.
Thank you!
- Greg_Deckler7 years agoCommunity Champion
OK, ImkeF might be able to help as well, she is an M guru.
- ImkeF7 years agoCommunity Champion
I believe the the equivalent M-syntax to the SQL-syntax you've mentioned in your original post would be this:
= Table.NestedJoin(Table1,,{"EmpID"},Table.Distinct(Table2, {"EmpID"}),{"EmpID"},"Table2",JoinKind.LeftOuter)So Greg_Deckler syntax was correct, just that it referred to the wrong table, as far as I can see.
- LivioLanzo7 years agoSolution Sage
- neharaj7 years agoRegular Visitor
Hey Greg,
How can we join via nestedjoin on multiple condition but with or conditrion.
Example: Select A.id ,A.Name B.Name,B.Course from A, B where (A.id=B.id Or A.Name = B.Name).
I was trying to do it using Merge query , I am able to select multiple column when joining from but A and B but I think it is taking And operator.