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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Help transforming a SQL join to a PowerQuery query.

I have been trying to transform this query:

 

SELECT
ms.groupid,
ms.statusid,
ms.Description,
ms.begintime,
ms.endtime,
i.uid
FROM DWH.AAAA AS ms
LEFT JOIN DWH.BBBB AS i ON
i.[begin] >= ms.begintime
AND i.[begin] < ms.endtime
AND i.re = ms.re
AND i.groupid = XY
AND i.visualisation = 'Z'

 

To the right equivelant in Powery Query. So far, the design page (DataFLow) has only allowed me to create this:

 

let
  Bron = Table.NestedJoin(
    #"MES - AAAA", {"begintime"}, 
    #"MES - BBBB", {"begin"}, "MES - BBBB", 
    JoinKind.LeftOuter)
in
  Bron

 

 

1 ACCEPTED SOLUTION

see attached for an implementation loosely based on your sample data.

 

 

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

TableA

IdDescriptionStartEnd
1qpwoei13.0014.00
2alskdj13.0014.00

 

TableB

Id1Id2Id3StartEndGroupidVisualisation
82312.3013.30XYZ
94512.3013.30XYZ

 

Joined

KeyAKeyB (concatenated)
18.2.3
9

9.4.5

 

 

see attached for an implementation loosely based on your sample data.

 

 

Anonymous
Not applicable

Dear sir, thanks for the assistence, i have been able to get this to work now in pbi. Im currently working on translating it to dataflow. Thanks again.

lbendlin
Super User
Super User

That looks ok-ish.  Where are you stuck? You need the other where conditions too?

 

Instead of Table.NestedJoin you can use Table.AddColumn with a custom column generator function that can implements your fuzzy join for you,

 

Note that your "left"  join is in fact an inner join since you have conditions from the "right"  table as part of the join.

Anonymous
Not applicable

Im stuck in the fact that i cannot use but only join on a specific column (equals).

As I said, use Table.AddColumn with a custom column generator.

 

Like so

 

NextStep = Table.AddColumn(LeftTable,"Join",(k)=> Table.SelectRows(RightTable,each
[begin] >= k[begintime]
and [begin] < k[endtime]
and re = k[re]
and groupid = XY
and visualisation = "Z"
))

 

 

This will be a guaranteed left join even with the conditions on the right.

 

Anonymous
Not applicable

I see what you are doing, cant get it to work though. Must add that im trying to set this up in DataFlow. Im wondering, even if this works, what does it look like when it finds miplt records, and therefore, would it be possible to create a calculated table for this such as:

TableA

IDDescriptionStarttime

Endtime

1pqowie13.00

14.00

2laksjd13.00

14.00

 

TableB

id1id2id3StartEndGroupIdVisualisation
81212.5013.30XYZ
91312.5013.30XYZ

 

Joined

TableAIdTableBId (concatenaded)
1823
1913
2823
2913

 

1 matches with 823 because it starts before 1300 and end before 1400. The same if true for 2. Basically we are matching events from TableA, with TableB, requiring events from TableB to have started before the TableA event and ended before the TableA event ended. 

 

So creating a table for setting up a one to many relationship

Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.


Anonymous
Not applicable

Tried to sanitize.

Paste sample TableA and sample TableB and indicate the expected result.

Anonymous
Not applicable

Hope this works better.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors