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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.