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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Tom_G
Helper II
Helper II

Matching Date Ranges Across Two Tables

Hi - I have two tables - one called ShopDeliveries and one called ShopHistory - the tables are linked together on the Shop Number column. 

 

The answer im looking for is the Shop Owner column on the ShopDeliveries table below. To create this column I need to match the shop delivery with the correct shop owner at the time the delivery was made. 

 

Thanks for your help!

 

ShopDeliveries

Shop NumberCallingIDArrival DateDeparture DateAmount DeliveredShop Owner
10034534567810/04/201811/04/201850John
10034686754613/01/202116/01/2021150John
10034729685720/07/202026/07/2020422Amy
10034798125630/11/202002/12/202036Justin

 

ShopHistory

ShopNumberShopOwnerStart DateEnd DateIndex
100345John01/01/201815/05/20183
100345Sara15/05/201811/11/20192
100345Lee11/11/2019 1
100346Tim19/08/201815/09/20203
100346Amy15/09/202018/12/20202
100346John18/12/2020 1
100347Bill14/04/201820/06/20203
100347Amy20/06/202031/10/20202
100347Justin31/10/2020 1
6 REPLIES 6
Jihwan_Kim
Super User
Super User

Hi, @Tom_G 

In order to achieve the above result, I created the model like below picture.

The link to pbix file is down below.

 

DeliveredShop Owner =
CALCULATE (
SELECTEDVALUE ( History[ShopOwner] ),
FILTER (
VALUES ( History[Start Date] ),
History[Start Date] <= SELECTEDVALUE ( Deliveries[Arrival Date] )
),
FILTER (
VALUES ( History[End Date] ),
History[End Date] >= SELECTEDVALUE ( Deliveries[Departure Date] )
|| History[End Date] = BLANK ()
)
)

 

Picture1.png

 

https://www.dropbox.com/s/48h3n2b8vl46bx6/TomG.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
amitchandak
Super User
Super User

@Tom_G , Try a new column like in ShopDeliveries

 


maxx(filter(ShopHistory, ShopHistory[ShopNumber] = ShopDeliveries[ShopNumber] && ShopDeliveries[Departure Date]>= ShopHistory[Start Date]
&& ShopDeliveries[Departure Date] >=ShopHistory[End Date]) ,ShopHistory[ShopOwner])

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

Thanks  @Jihwan_Kim  - the measure produces the right result. For the sake of integration in my model I was looking for a calculated column.

 

I tried the DAX from @amitchandak  for the calculated column but it's not quite giving the expected result (see new column below). Any ideas how to tweak this? Thanks

 

ShopNumber     Arrival Date        Departure Date Shop Owner       New Column

100345  10/04/2018         11/04/2018         John     

100346  13/01/2021         16/01/2021         John      Tim

100347  20/07/2020         26/07/2020         Amy       Bill

100347  30/11/2020         02/12/2020         Justin    Justin

Hi, @Tom_G 

Can you try the below for the calculated column ?

 

DeliveredShop Owner column =
CALCULATE (
MAX( History[ShopOwner]),
 
FILTER (
VALUES ( History[Start Date] ),
History[Start Date] <= Deliveries[Arrival Date]
),
FILTER (
VALUES ( History[End Date] ),
History[End Date] >= Deliveries[Departure Date]
|| History[End Date] = BLANK ()
)
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim , @amitchandak - would you know how to translate Jihwan's calculated column below into the M language, so I could create the column in the Power Query Editor instead?  

Thanks a lot 

 

DeliveredShop Owner column =
CALCULATE (
MAX( History[ShopOwner]),
 
FILTER (
VALUES ( History[Start Date] ),
History[Start Date] <= Deliveries[Arrival Date]
),
FILTER (
VALUES ( History[End Date] ),
History[End Date] >= Deliveries[Departure Date]
|| History[End Date] = BLANK ()
)
)

Thanks a lot @Jihwan_Kim for your help - it works on the test file! I also tweaked the query from @amitchandak below, which also seems to work on the test file.

Unfortunately both queries are a strain on memory consumption on my full data set so BI is having issues processing them.

 

Column = maxx(filter(ShopHistory, ShopHistory[ShopNumber] = ShopDeliveries[ShopNumber] && ShopDeliveries[Arrival Date]>= ShopHistory[StartDate]
&& ShopDeliveries[Departure Date] <=ShopHistory[EndDate]
|| ShopHistory[ShopNumber] = ShopDeliveries[ShopNumber] && ShopDeliveries[Arrival Date]>= ShopHistory[StartDate] && ISBLANK(ShopHistory[EndDate])) ,ShopHistory[ShopOwner])

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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
Top Kudoed Authors