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! Request now

Reply
clteh9
Helper I
Helper I

match record with nearest datetime

Hi, 

 

I have 2 tables and would like to match the record with the nearest date. 

 

table 1:

clteh9_0-1669872830810.png

 

table 2:

clteh9_1-1669872844305.png

 

expected result:

clteh9_2-1669872869140.png

 

thanks

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@clteh9 

pls try this 

Column = 
VAR _l=maxx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table'[end time]>='Table 2'[last_dt]),'Table 2'[last_dt])
VAR _n=minx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table'[end time]<'Table 2'[last_dt]),'Table 2'[last_dt])
VAR _d1='Table'[end time]-_l
VAR _d2=abs(_n-'Table'[end time])
VAR _compare=min(_d1,_d2)
return  if(_compare=_d1,maxx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table 2'[last_dt]=_l),'Table 2'[value]),maxx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table 2'[last_dt]=_n),'Table 2'[value]))

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
ryan_mayu
Super User
Super User

@clteh9 

pls try this 

Column = 
VAR _l=maxx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table'[end time]>='Table 2'[last_dt]),'Table 2'[last_dt])
VAR _n=minx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table'[end time]<'Table 2'[last_dt]),'Table 2'[last_dt])
VAR _d1='Table'[end time]-_l
VAR _d2=abs(_n-'Table'[end time])
VAR _compare=min(_d1,_d2)
return  if(_compare=_d1,maxx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table 2'[last_dt]=_l),'Table 2'[value]),maxx(FILTER('Table 2','Table'[item]='Table 2'[item]&&'Table 2'[last_dt]=_n),'Table 2'[value]))

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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