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
Analitika
Post Prodigy
Post Prodigy

Editor Lookup nearest date

I need in editor add column which must found currency value at operation date, if currency value not exists on operation date, then take last nearest date value

 

Table1

Date | AddColumn

2020-01-01 | 

2020-01-05 |

 

 

Table2
Date | Currency | Value

2020-01-01 | USD | 0.8124545
2020-01-03 | USD | 0.8524545
2020-01-06 | USD | 0.8924545

 

 

expected result

 

Table1

Date | AddColumn

2020-01-01 | 0.8124545

2020-01-05 | 0.8524545

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Analitika , Try a new column table 1

New column =
var _excat = maxx(filter(Table2, Table1[Date] = Table2[Date] ),Table2[Value])
var _min = datediff(Table1[Date], maxx(filter(Table2, Table1[Date] < Table2[Date] ),Table1[Date]),day)
var _max = datediff(Table1[Date],minx(filter(Table2, Table1[Date] > Table2[Date] ),Table1[Date]),day)
return
if(not(isblank(_excat)),_excat, if(abs(_min) <abs(_max),maxx(filter(Table2, Table2[Date] =_min ),Table2[Value]),,maxx(filter(Table2, Table2[Date] =_max ),Table2[Value])))

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Analitika , Try a new column table 1

New column =
var _excat = maxx(filter(Table2, Table1[Date] = Table2[Date] ),Table2[Value])
var _min = datediff(Table1[Date], maxx(filter(Table2, Table1[Date] < Table2[Date] ),Table1[Date]),day)
var _max = datediff(Table1[Date],minx(filter(Table2, Table1[Date] > Table2[Date] ),Table1[Date]),day)
return
if(not(isblank(_excat)),_excat, if(abs(_min) <abs(_max),maxx(filter(Table2, Table2[Date] =_min ),Table2[Value]),,maxx(filter(Table2, Table2[Date] =_max ),Table2[Value])))

TY, it works with some addition correction, as you in  return use _max but need date

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.