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

Joining 2 tables with condition

Hi guys. Hope you can help. I am trying to join 2 tables in PBI with a filter/condition.
I have a SQL syntax but struggling to convert it to DAX (PBI).
Table1:CHECKEDTICKETS
Table2:TRANSACTIONS

 

SQL look slike this:

"...WHERE
( CHECKEDTICKETS.TICKETNO = TRANSACTIONS.RECEIPT_NO and CHECKEDTICKETS.CHT_CAL_ID between
TRANSACTIONS.CAL_CAL_ID and TRANSACTIONS.V_CAL_CAL_ID )
GROUP BY
CHECKEDTICKETS.TICKETNO

TRANSACTIONS.CAL_CAL_ID and TRANSACTIONS.V_CAL_CAL_ID are basically dates but data type is number.

3 REPLIES 3
amitchandak
Super User
Super User

Assuming CHECKEDTICKETS is a master table and has a primary key key1. lease add index column here in power bi

populate that in TRANSACTIONS

 

CHECKEDTICKETS Key in TRANSACTIONS = minx(filter(CHECKEDTICKETS ,CHECKEDTICKETS[TICKETNO] = TRANSACTIONS[RECEIPT_NO] && CHECKEDTICKETS[CHT_CAL_ID] >=
TRANSACTIONS[CAL_CAL_ID] && CHECKEDTICKETS[CHT_CAL_ID]<= TRANSACTIONS[V_CAL_CAL_ID ]),CHECKEDTICKETS [Key1])

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable


Table = NATURALLEFTOUTERJOIN ( CHECKEDTICKETS, FILTER ( CROSSJOIN ( CHECKEDTICKETS, TRANSACTIONS ),
CHECKEDTICKETS[TICKETNO] = TRANSACTIONS[RECEIPT_NO] CHECKEDTICKETS[CHT_CAL_ID] >= TRANSACTIONS[V_CAL_CAL_ID] && CHECKEDTICKETS[CHT_CAL_ID] <= TRANSACTIONS[V_CAL_CAL_ID] ) )

 

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos. 

Anonymous
Not applicable

Or You may refer to the following DAX that adds a calculated column.

 

Check below link 

https://community.powerbi.com/t5/Desktop/conditional-join/td-p/339960

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

 

 

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.