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
Kenneth_37
Frequent Visitor

Conditional joins

Hi, I'm new to using power bi and usually work with SSMS. Hoping to find out if what I want to do is possible in power bi.  I think it's best if I use an example.

 

Table1 columns: StartDate, EndDate, Ward, AvailableBeds

Table2 columns: Patient, Ward, Date, LengthOfStay

 

I'm hoping to join the two tables above, based on the ward. However, table1 will have multiple records for the wards as the AvailableBeds will change on a periodic basis.

 

For example Ward A might have:

1 record with a StartDate of 01/01/2020, EndDate 31/03/2020;

1 record with StartDate of 01/04/2020, EndDate 30/06/2020

and a final record with StartDate of 01/07/2020, EndDate 31/12/2021;

 

In SSMS I would join on ward with the condition that Table2 Date, is between Table1 StartDate and EndDate.

 

What would be the best approach in PowerBI?

 

Thanks.

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Kenneth_37 ,

 

Check the following steps in Power Query Editor.

Step1# Inner join merge table1 and table2 with [Ward] and expand tables.

Step2# Create a custom column with below query:

Column = if [Table2.Date] >= [StartDate] and [Table2.Date] <= [EndDate] then 1 else 0

Step3# Filter table with column = 1.

Result would be shown as below:

Capture.PNG

Then you can delete and rename the rows if you need.

Pbix as attached.

 

Best Regards,

Jay

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Kenneth_37 ,

 

Check the following steps in Power Query Editor.

Step1# Inner join merge table1 and table2 with [Ward] and expand tables.

Step2# Create a custom column with below query:

Column = if [Table2.Date] >= [StartDate] and [Table2.Date] <= [EndDate] then 1 else 0

Step3# Filter table with column = 1.

Result would be shown as below:

Capture.PNG

Then you can delete and rename the rows if you need.

Pbix as attached.

 

Best Regards,

Jay

Thank you! I think this might just work. I'm still working through it and will report back.

Kenneth_37
Frequent Visitor

I don't quite think I explained what I'm after well enough.

 

Because the AvailableBeds changes from month to month and I want to display a yearly snapshot, I would require all of the records from table 1 to still be used.

 

Thanks for your help anyway.

Anonymous
Not applicable

Hello @Kenneth_37 

You can join both the tables based on the ward and provide the start and end date slicer.

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.