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
DannyMiletic
Frequent Visitor

Comparing dates from 2 tables to select a value for the exchange rate

Hi Power BI Community - can anyone help me with the measure that I need to write to accomplish this? I am really striking out on this and need help. I have 2 tables; Table A - exchange rate table with rates posted at the end of each month, and table B - invoice table with dates, amounts in local currency and currency type. I need a measure that will compare the invoice_date and currency_ID to the exchange rate table and bring back the correct rate. The exchange rates are posted at the end of the month so that the 7/31/2020 exchange rate is applied to invoices during the month of July.

 

DannyMiletic_1-1685482988328.png

 

 

 

1 ACCEPTED SOLUTION
MarkLaf
Solution Sage
Solution Sage

Assuming VALID_UNTIL and CURRENCYFROM_ID are a composite key for Table A, you could add a calculated column to both tables and relate them that way to then pull over corresponding exchange rate. Calculated column DAX would look like:

 

'Table A'[ExId] = 
VAR _dt = 'Table A'[VALID_UNTIL] 
VAR _exId = 'Table A'[CURRENCYFROM_ID]
RETURN
_exId  * 10^8 
+ YEAR( _dt  ) * 10^4 
+ MONTH( _dt ) * 10^2 
+ DAY( _dt )

'Table B'[ExId] = 
VAR _dt = EOMONTH( 'Table B'[invoice_date], 0 )
VAR _exId = 'Table B'[Currency_ID]
RETURN
_exId  * 10^8 
+ YEAR( _dt  ) * 10^4 
+ MONTH( _dt ) * 10^2 
+ DAY( _dt )

 

 

View solution in original post

3 REPLIES 3
MarkLaf
Solution Sage
Solution Sage

Assuming VALID_UNTIL and CURRENCYFROM_ID are a composite key for Table A, you could add a calculated column to both tables and relate them that way to then pull over corresponding exchange rate. Calculated column DAX would look like:

 

'Table A'[ExId] = 
VAR _dt = 'Table A'[VALID_UNTIL] 
VAR _exId = 'Table A'[CURRENCYFROM_ID]
RETURN
_exId  * 10^8 
+ YEAR( _dt  ) * 10^4 
+ MONTH( _dt ) * 10^2 
+ DAY( _dt )

'Table B'[ExId] = 
VAR _dt = EOMONTH( 'Table B'[invoice_date], 0 )
VAR _exId = 'Table B'[Currency_ID]
RETURN
_exId  * 10^8 
+ YEAR( _dt  ) * 10^4 
+ MONTH( _dt ) * 10^2 
+ DAY( _dt )

 

 

Thank you - this was very helpful!

Thanks - I will try it.

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.