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

Closest lookup date in Power Query / M-language

Hi,

In the Excel table "Purchases" I want to add a New column where I use the Date row to lookup an exchange rate in the "Exchange Rates" table and calculate the new currency cost column based on the original currency and the exchange rate.

 

Table1.png      Table2.png

 

My challenge is that purchase lines may be registered on any date, but the exchange rates are not available for weekends and holidays dates. You can see that there is a purchase row registered on the date 03.08.2019, but there is no exchange rate available for that date in the "Exchange Rate" table because this is a Saturday.

 

Can you please help me how to solve this in Power Query / M language?

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try this new custom column

 

=let mydate=[Date] in 
Table.Max(
Table.SelectRows(#"Exchange Rates",each [Date] <= mydate),"Date")[Rate]

Regards
Zubair

Please try my custom visuals

View solution in original post

1 REPLY 1
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try this new custom column

 

=let mydate=[Date] in 
Table.Max(
Table.SelectRows(#"Exchange Rates",each [Date] <= mydate),"Date")[Rate]

Regards
Zubair

Please try my custom visuals

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.

Top Solution Authors