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
Anonymous
Not applicable

Join tables on "greater than" condition

Hello,

 

I have two tables that look like this:

Untitled.png

I need "Time2" from "Table 2" in "Table 1", on these conditions:

a. Table 1 [ID] = Table 2[ID]

b. Table 1 [Date] = Table 2[Date]

c. Table 2[Time2] is the smallest value that fulfils Table 2[Time2] > Table 1[Time1]

 

For the example of the two tables above, this is the expected result:

Untitled.png

Can you please help me to do this? 

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

hi @Anonymous 

how about creating a calculated column like this in table 1:

Time 2 =
CALCULATE (
    MIN ( Table2[Time2] );
    FILTER (
        ALL ( Table2 );
        Table2[Date ] = Table1[Date]
            && Table2[ID] = Table1[ID]
            && Table2[Time2] > Table1[Time 1]
    )
)

View solution in original post

2 REPLIES 2
sturlaws
Resident Rockstar
Resident Rockstar

hi @Anonymous 

how about creating a calculated column like this in table 1:

Time 2 =
CALCULATE (
    MIN ( Table2[Time2] );
    FILTER (
        ALL ( Table2 );
        Table2[Date ] = Table1[Date]
            && Table2[ID] = Table1[ID]
            && Table2[Time2] > Table1[Time 1]
    )
)
Anonymous
Not applicable

Thanks a lot, that is exactly what I needed!

 

For those that want to use it in the future, just a comment on two small syntax errors: the ";" should be ",". Otherwise the query works directly. 

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.