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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Lookup between two dates

Hi All,

 

I have two tables/queries (snippet below) and what I am trying to do is match the driver from the table/query 1 to table/query 2 based on the following criteria - Car (Table2) matches Car (Table1) and Report Date (Table2) falls inbetween Commence date (Table1) and End Date (Table1)

 

Table/Query1

 

CarDriverCommence DateEnd Date
NissanWill01/01/2018 15:0601/04/2018 10:00
NissanCharlie01/04/2018 10:0002/05/2018 09:00
FiatPeter25/03/2018 00:0031/04/2018 11:54
MazdaJan03/02/2018 13:4304/05/2018 09:36
MazdaJan04/05/2018 09:3621/05/2018 11:00
MazdaBen21/05/2018 11:0009/06/2018 13:43

 

Table/Query2

 

CarReport Date
Nissan31/04/2018 11:33
Fiat25/03/2018 00:00
Mazda07/05/2018 13:24

 

Therefore, for the above you would finish with the below

 

 

CarReport DateDriver
Nissan31/04/2018 11:33Charlie
Fiat25/03/2018 00:00Peter
Mazda07/05/2018 13:24Ben

 

Does anyone have any ideas?

 

Many Thanks,

 

Jack

1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

Are you looking to do it with a calculated table?

 

 

Table =
ADDCOLUMNS (
    Table2,
    "Driver",
    VAR tCar = Table2[Car]
    VAR Dte = Table2[Report Date]
    RETURN
        CALCULATE (
            VALUES ( Table1[Driver] ),
            Table1[Car] = tCar,
            Table1[Commence Date] <= dte,
            Table1[End Date] >= Dte
        )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

1 REPLY 1
LivioLanzo
Solution Sage
Solution Sage

Are you looking to do it with a calculated table?

 

 

Table =
ADDCOLUMNS (
    Table2,
    "Driver",
    VAR tCar = Table2[Car]
    VAR Dte = Table2[Report Date]
    RETURN
        CALCULATE (
            VALUES ( Table1[Driver] ),
            Table1[Car] = tCar,
            Table1[Commence Date] <= dte,
            Table1[End Date] >= Dte
        )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon & SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.