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
brett_walton
Helper II
Helper II

Find entry whose date time is less than but closest to fact table

I am looking for logic to determine how to pull the following data 

 

I have a fact table that has transaction date and time and computer per transaction the second table is the device table showing who was logged into the device (there is no log out). My intended logic will be to link date, and device ID and then find the time that is the first time found less the log in time from the fact table . So the first entry I want to determine BOB was logged and second ROB

 

                     Date      Time        Device

Example :      1/1/17   08:10:53   RFGN3550            

                     1/1/17   10:13:40   RFGN3560

 

I have a device Log table that says who was logged into that device 

                 Log in Date    Time       Device          Person

Example:           1/1/17   08:00:00   RFGN3550     BOB 

                         1/1/17  09:00:00    RFGN3550     MARY  

                         1/1/17  09:00:00    RFGN3560     SAM

                         1/1/17  10:00:00    RFGN3550    ROB

2 ACCEPTED SOLUTIONS
OwenAuger
Super User
Super User

This seems to have been deemed an M question, but here is one of those "dime a dozen" DAX solutions:

PBIX sample

 

 

Capture.PNG

 

 Calculated column in Transactions:

Person = 
VAR TransactionDateTime = Transactions[DateTime]
RETURN
    CALCULATE (
        //Arbitrary tie-breaker
        FIRSTNONBLANK ( Logins[Person], 0 ),
        CALCULATETABLE (
            LASTNONBLANK ( Logins[DateTime], 0 ),
            Logins[DateTime] <= TransactionDateTime
        )
    )

 

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

@brett_walton

I suspect you've modified @OwenAuger's formula to only look at your Time columns!

 

Note that he checks a Date/Time column.

 

So to address this create a Date-Time Column in both tables like this

Date-Time = [Date]&" "&[Time]

Both of these columns will default to Text - so you need to convert them to Data Type - Date/Time - again in both tables.

 

This should resolve it!

 

Good Luck! Smiley Happy

View solution in original post

15 REPLIES 15

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.