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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Matching data from a date range and an ID across two tables

I am working on a report that has two tables like the ones shown

 

Table 1

UserLoginTimeLogoutTimeSessionKey
A11/12/2019 12:0011/12/2019 15:00key1
B11/12/2019 7:0011/12/2019 10:00key2
A11/12/2019 17:0011/12/2019 18:00key3

 

Table 2

UserActivityTime
A11/12/2019 12:30
A11/12/2019 14:00
B11/12/2019 8:00
A11/12/2019 17:30
B11/12/2019 9:00

 

I need a way to match each row in Table 2 with a row in Table 1 by matching the User as well as making sure the ActivityTime is between the LoginTime and LogoutTime. Is there a way to do this?

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can create column in table2 like DAX below.

 

SessionKey_matched =
MAXX (
    TOPN (
        1,
        FILTER (
            'Table 1',
            'Table 1'[User] = 'Table 2'[User]
                && 'Table 1'[LogoutTime] > 'Table 2'[ActivityTime]
                && 'Table 1'[LoginTime] <= 'Table 2'[ActivityTime]
        ),
        'Table 1'[LoginTime] && 'Table 1'[LogoutTime], DESC
    ),
    'Table 1'[SessionKey]
)

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can create column in table2 like DAX below.

 

SessionKey_matched =
MAXX (
    TOPN (
        1,
        FILTER (
            'Table 1',
            'Table 1'[User] = 'Table 2'[User]
                && 'Table 1'[LogoutTime] > 'Table 2'[ActivityTime]
                && 'Table 1'[LoginTime] <= 'Table 2'[ActivityTime]
        ),
        'Table 1'[LoginTime] && 'Table 1'[LogoutTime], DESC
    ),
    'Table 1'[SessionKey]
)

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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