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
ThomasSan
Helper III
Helper III

Using the latest figure from one table and use it in another

Hi,

 

I am attempting to use PowerBI as a simulator tool. My goal is to calculate non-Euro sales figures to Euro values by using the latest exchange rate depending on the settings of my date slicer. 

 

I have an exchange rate table (named "ER") that has the strucutre

DateYearMonthExchange Rate to EuroCurrency
1.1.1010155AAA
1.1.1010156BBB
1.2.1010257AAA
1.2.1010258BBB
1.1.2020159AAA
1.1.2020160BBB
1.2.2020261AAA
1.2.2020262BBB

and I have a sales table (named "Sales") that has the structure

DateYearMonthSales in Local CurrencyCountryCurrency
1.2.20202856bbBBB
1.2.10102566bbBBB
1.1.10101545aaAAA
1.1.20201443aaAAA
1.2.10102324aaAAA
1.1.20201231bbBBB
1.1.10101212bbBBB
1.2.20202112aaAAA

and I have a simple date table (named "Date") that is connected to the sales table with a 1-to-many cardinality.

What is the dax command that I can use in order to map the correct exchange rate figure to each currency in my sales table (depending on the settings of the date slicer)?

 

My current formula looks as follows:

 

 

SalesEURO latest ER = 

var saleslocal=
sum(Sales[Sales in Local Currency])

var ERlatest=
CALCULATE(
    sum(ER[Exchange Rate]),
    filter(
        'ER',
        ER[Date].[Date] = max('Date'[Date])
        )
    )

return saleslocal*ERlatest

 

 

I feel like I am overthinking this...

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @ThomasSan ,

Please try to create a measure with below dax formula:

Measure =
VAR _date =
    MAX ( 'Date'[Date] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), 'Table'[Date] <= _date )
VAR latest_date =
    MAXX ( tmp, [Date] )
VAR cur_currency =
    SELECTEDVALUE ( 'Table 2'[Currency] )
VAR cur_currency_sale =
    SELECTEDVALUE ( 'Table 2'[Sales in Local Currency] )
VAR _rate =
    CALCULATE (
        MAX ( 'Table'[Exchange Rate to Euro] ),
        'Table'[Date] = latest_date,
        'Table'[Currency] = cur_currency,
        ALL ( 'Table' )
    )
RETURN
    cur_currency_sale * _rate

vbinbinyumsft_0-1694501703581.png

For more details, please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
ThomasSan
Helper III
Helper III

Hi @v-binbinyu-msft 

 

that looks really good (and I learnt something new today about DAX). Thanks a lot!

v-binbinyu-msft
Community Support
Community Support

Hi @ThomasSan ,

Please try to create a measure with below dax formula:

Measure =
VAR _date =
    MAX ( 'Date'[Date] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), 'Table'[Date] <= _date )
VAR latest_date =
    MAXX ( tmp, [Date] )
VAR cur_currency =
    SELECTEDVALUE ( 'Table 2'[Currency] )
VAR cur_currency_sale =
    SELECTEDVALUE ( 'Table 2'[Sales in Local Currency] )
VAR _rate =
    CALCULATE (
        MAX ( 'Table'[Exchange Rate to Euro] ),
        'Table'[Date] = latest_date,
        'Table'[Currency] = cur_currency,
        ALL ( 'Table' )
    )
RETURN
    cur_currency_sale * _rate

vbinbinyumsft_0-1694501703581.png

For more details, please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

some_bih
Super User
Super User

Hi @ThomasSan please check dedicated video for your / similar topic

https://www.sqlbi.com/articles/currency-conversion-in-power-bi-reports/ 

Hope this help, kudos appreciated.





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

Proud to be a Super User!






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.