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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.