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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
andrewpirie
Resolver II
Resolver II

Joining/Merging where TABLE1.DateTime is between TABLE2.StartDateTime and TABLE2.EndDateTime

I have a table named "SnapshotDateTimes" with a column ReferenceDateTime.

 

I have another table that holds snapshotted data of a customer record, and a column that identifies the from and two dates that this record is valid (a type 2 SCD). The customer record has the fields Customer_ID, FirstName, LastName, Start_Date, End_Date.

 

I would like to produce a table with the fields below, by joining SnapshotDateTimes to Customers where SnapshotDateTimes.ReferenceDateTime is between Customers.Start_Date and Customers.End_Date, using PowerQuery filtering.

 

[SnapshotDateTimes.]ReferenceDateTime, [Customers].Customer_ID, [Customers].FirstName, [Customers.]Surname.

 

RADACAD.com has an example of what I hope to achieve at Dates Between Merge Join in Power Query, however for me I am concerned that finding all possible dates between my Customers.Start_Date and Customers.End_Date, then joining to SnapshotDateTimes.ReferenceDateTime on individual dates would be poorly performing.

 

I'm looking for what would be done by the below in T-SQL:

SELECT ...
FROM SnapshotDateTimes
    INNER JOIN Customers
        ON SnapshotDateTimes.ReferenceDateTime BETWEEN SnapshotDateTimes.Start_Date AND SnapshotDateTimes.End_Date

 

Can anyone point me in the right direction using PowerQuery without needing an in-between "dates" list? I'm imagining I should be able to do something like a foreach over the rows in SnapshotDateTimes, then use Table.SelectRows against the Customers table, filtering on where SnapshotDateTimes.ReferenceDateTime is between Customers.Start_Date and Customers.End_Date.

 

If this just isn't possible, then it would be awesome to know that too, I may need to rework this to have the limitation of one-snapshot-per-day and use the example linked above.

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @andrewpirie,


Nope, I don't think it is possible.


These tables has relationship with expand date range which not real existed in table column, you need to create new column to store fully detail range dates to link two tables.

 

Maybe you can try to use T-sql to create this template link table.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @andrewpirie,


Nope, I don't think it is possible.


These tables has relationship with expand date range which not real existed in table column, you need to create new column to store fully detail range dates to link two tables.

 

Maybe you can try to use T-sql to create this template link table.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks @v-shex-msft - it's great to have an experienced answer on this, I'll try another optimization technique instead of going in circles on this one :).

 

Andrew

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.