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

exchange rate changes, but only gets highest number.

Hi all. 
I have a problem with getting the right exchange rate, because it changes over time. Not everyday but almost once in a month. 
I have two tabels, some with the orders and another with exchange rate. See below: 

SalesOrderLines: 

SalesOrderNumberLineAmountCurrency
SO20459156,69EUR
SO2537829.800,71EUR
SO309722.069,64

USD

 

ExchangeRates: 

LastDatoFromCurrencyRate
31/07/2020EUR7,44
31/07/2020USD

6,31

31/08/2020EUR

7,45

 

In the SalesOrderLines Tabel i make a new column that is called Rate. There i want the newest exchange rate shown. 
But when i use the following statement, i get the biggest exchange rate - i think its the MAX statement, but i dont know what else to use. 

Rate =
CALCULATE( MAX(ExchangeRates[Rate]);
FILTER( ExchangeRates;
ExchangeRates[StartDate].[Date] <= Today();

Filter ( ExchangeRates; ExchangeRates[FromCurrency] = SalesOrderLines[CurrencyCode])
)

I cant check on a date in SalesOrderLines Table because its not allways filled out. Så I just want to check the date on ExchangeRates Tabel is "arround" today. 

Is there any who got a solution? 

Thx in advance. 


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

Hi, @SofieSwensson 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

SalesOrderLines:

c1.png

 

ExchangeRates:
c2.png

 

You may create a calculated column as below.

NewRate = 
CALCULATE(
    MAX(ExchangeRates[Rate]),
    FILTER(
        ExchangeRates,
        [LastDate]=
        CALCULATE(
            MAX(ExchangeRates[LastDate]),
            FILTER(
                ExchangeRates,
                [LastDate]<=TODAY()
            )
        )&&
        [FromCurrency]=EARLIER(SalesOrderLines[Currency])
    )
)

 

Today is 9/21/2020. Here is the result.

c3.png

 

Best Regards

Allan

 

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
v-alq-msft
Community Support
Community Support

Hi, @SofieSwensson 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

SalesOrderLines:

c1.png

 

ExchangeRates:
c2.png

 

You may create a calculated column as below.

NewRate = 
CALCULATE(
    MAX(ExchangeRates[Rate]),
    FILTER(
        ExchangeRates,
        [LastDate]=
        CALCULATE(
            MAX(ExchangeRates[LastDate]),
            FILTER(
                ExchangeRates,
                [LastDate]<=TODAY()
            )
        )&&
        [FromCurrency]=EARLIER(SalesOrderLines[Currency])
    )
)

 

Today is 9/21/2020. Here is the result.

c3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@SofieSwensson , Try like

 

Rate =
CALCULATE( lastnonblankvalue(ExchangeRates[LastDato], max(ExchangeRates[Rate]));
FILTER( ExchangeRates;
ExchangeRates[StartDate].[Date] <= Today()) && ExchangeRates[FromCurrency] = SalesOrderLines[CurrencyCode])

 

but it is measure you need some changes

amitchandak , I get the error that Today returns a true/false false, and thats also true. 
So can i use something else to check up against the 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.