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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
JeffT
Frequent Visitor

Join the closest datetime's value of one table to the datetime of another table

Hi guys, 

 

I have an issue. There are 2 tables, table 1 has datetime and value, value can either be "on" or "off". Table 2 has datetime and value, value can either be "good" or "suspect". My challenge is I want to join table 2 to table 1 based on datetime, but the datetimes of each table do not match each other, I am trying to map the closest/previous datetime that matches the two tables and join them.

 

Note, the tables row count are not the same (one is longer than the other)

 

Ex.

table 1 

2022-01-02 8:29:08 PM

OFF

2022-01-06 10:23:06 AMON
2022-01-06 1:20:26 PMOFF
2022-01-06 1:55:16 PMOFF
2022-01-08 9:54:52 PMON

 

table 2

2022-01-01 9:48:19 AMGood
2022-01-01 5:44:54 PMSuspect
2022-01-02 1:46:30 AMSuspect
2022-01-02 9:48:06 AMGood
2022-01-02 5:44:41 PMSuspect
2022-01-03 1:46:17 AMGood
2022-01-03 9:47:53 AMSuspect
2022-01-03 5:44:28 PMGood
2 REPLIES 2
JeffT
Frequent Visitor

Thank you so much for your help!!!!

barritown
Super User
Super User

Hi @JeffT,

If I have correctly understood the task, you need a calculated column like this:

barritown_0-1684308931587.png

Here is the same code in plain text for convenience:

Status = 
VAR CurrentTimestamp = [Timestamp]
VAR Timestamp_Tbl2 = MAXX ( FILTER ( Tbl2, Tbl2[Timestamp] <= CurrentTimestamp ), Tbl2[Timestamp] )
RETURN LOOKUPVALUE ( Tbl2[Status], Tbl2[Timestamp], Timestamp_Tbl2 )

 Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors