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

Dynamic currency conversion help

Hello Experts,
I need some help with Dynamic currency conversion.

Here is my request
I have a Fact table with three dates with three amounts(below screenshot). When the user selects a currency code, these measures should be filtered by those dates with conversion rates.

I appreciate any help you can provide.

Puja_0-1665455927807.png

 

This is Exchange reate table .

 

Puja_1-1665456003224.png

Sample data

Sales OrganizationPlantInvoice DateInvoiced Net SalesDate NetGI Net Sales Item Month/Year Net Sales
 JV Commercial1/1/2022 0:00300010/1/2019 0:00115195123.710/1/2019 0:00100
 JV Commercial1/2/2022 0:00500010/2/2019 0:00107449259.810/2/2019 0:0020000
 JV Commercial1/3/2022 0:00700010/3/2019 0:00104248420.910/3/2019 0:0039900
 JV Commercial1/4/2022 0:00900010/4/2019 0:0088383536.6710/4/2019 0:0059800
 JV Commercial1/5/2022 0:001100010/5/2019 0:0081430085.719/1/2018 0:0079700
 JV Commercial1/6/2022 0:001300010/6/2019 0:0080904489.229/2/2018 0:0099600
 JV Commercial1/7/2022 0:00150002/1/2019 0:0079026069.439/3/2018 0:00119500
 JV Commercial1/8/2022 0:00170002/2/2019 0:0078458087.599/4/2018 0:00139400
 JV Commercial1/9/2022 0:00190002/3/2019 0:0076410505.669/5/2018 0:00159300
 JV Commercial1/10/2022 0:00210002/4/2019 0:0074064267.979/6/2018 0:00179200
 JV Commercial1/11/2022 0:00230002/5/2019 0:0070108154.6411/1/2019 0:00199100
 JV Commercial2/1/2022 0:00250002/6/2019 0:0067304229.1411/2/2019 0:00219000
 JVRiver2/2/2022 0:00270002/7/2019 0:0062473692.1711/3/2019 0:00238900
 JVRiver2/3/2022 0:00290002/8/2019 0:0061522920.4611/4/2019 0:00258800
 JVRiver2/4/2022 0:00310002/1/2022 0:0059491254.8711/5/2019 0:00278700
 JVRiver2/5/2022 0:00330002/2/2022 0:0058135935.038/1/2016 0:00298600
IURiver3/1/2022 0:00350002/3/2022 0:0057121334.088/2/2016 0:00318500
IURiver3/2/2022 0:00370002/4/2022 0:0056813023.248/3/2016 0:00338400
IURiver3/3/2022 0:003900010/1/2018 0:0056641166.68/4/2016 0:00358300
IURiver3/4/2022 0:004100010/2/2018 0:0054169527.838/5/2016 0:00378200
IURiver3/5/2022 0:004300010/3/2018 0:0054081676.794/1/2019 0:00398100
IURiver3/6/2022 0:004500010/4/2018 0:0053966513.674/2/2019 0:00418000
IUCS3/7/2022 0:004700010/5/2018 0:0052486989.564/3/2019 0:00437900
IUCS6/1/2022 0:004900010/6/2018 0:0051375353.614/4/2019 0:00457800
IUCS6/2/2022 0:005100010/7/2018 0:0050744893.164/5/2019 0:00477700
IUCS6/3/2022 0:005300010/8/2018 0:0050261684.954/6/2019 0:00497600
IUCS6/4/2022 0:005500010/9/2018 0:0048337385.633/1/2022 0:00517500
IUCS6/5/2022 0:0057000#############48163206.643/2/2022 0:00537400
IUCS6/6/2022 0:00590002/1/2020 0:0047219778.823/3/2022 0:00557300
IUCS6/7/2022 0:006100010/1/2017 0:0046234021.113/4/2022 0:00577200
IUCS6/8/2022 0:00630008/1/2018 0:0045717685.873/5/2022 0:00597100
IUCS6/9/2022 0:00650008/2/2018 0:0045067409.823/6/2022 0:00617000
IUCS6/10/2022 0:00670008/3/2018 0:0044997749.186/1/2019 0:00636900
IUCS6/11/2022 0:00690008/4/2018 0:0044794696.866/2/2019 0:00656800
AACS6/12/2022 0:00710008/5/2018 0:0044206922.076/3/2019 0:00676700
AACS9/1/2022 0:00730008/6/2018 0:0044091486.936/4/2019 0:00696600
AACS9/2/2022 0:00750008/7/2018 0:0043499169.066/5/2019 0:00716500

 

1 ACCEPTED SOLUTION

try

Invoiced net sales converted =
VAR SelectedCurrency =
    SELECTEDVALUE ( 'Exch rate'[Currency] )
RETURN
    IF (
        NOT ISBLANK ( SelectedCurrency ),
        SUMX (
            'Table',
            VAR ReferenceDate = 'Table'[Invoice date]
            VAR ReferenceAmount = 'Table'[Invoiced net sales]
            VAR ExchRate =
                CALCULATE (
                    MAX ( 'Exch rate'[_EXCH_RATE] ),
                    'Exch rate'[Currency] = SelectedCurrency,
                    'Exch rate'[Date] = DATE( YEAR( ReferenceDate), MONTH(ReferenceDate),1)
                )
            RETURN
                ExchRate * ReferenceAmount
        )
    )

View solution in original post

7 REPLIES 7
johnt75
Super User
Super User

Try

Invoiced net sales converted =
VAR SelectedCurrency =
    SELECTEDVALUE ( 'Exch rate'[Currency] )
RETURN
    IF (
        NOT ISBLANK ( SelectedCurrency ),
        SUMX (
            'Table',
            VAR ReferenceDate = 'Table'[Invoice date]
            VAR ReferenceAmount = 'Table'[Invoiced net sales]
            VAR ExchRate =
                CALCULATE (
                    MAX ( 'Exch rate'[_EXCH_RATE] ),
                    'Exch rate'[Currency] = SelectedCurrency,
                    'Exch rate'[_FROM_DT] <= ReferenceDate
                        && 'Exch rate'[_TO_DT] >= ReferenceDate
                )
            RETURN
                ExchRate * ReferenceAmount
        )
    )

Hi @johnt75 , 

Thanks for the solution.

I tested your solution and it looks like its only reading data on 1st of each month.

In exchange table , I have ave rate by month.

Ex:  date             Exch  AVE rate

     6/1/2020       0.12

     7/1/2020       0.09

     8/1/2020       1.19

 

 

Example : 6/1/2020  Converting correctly.

                6/2/2020 I see blank althought there is data.

 

Could you please help.

Thank you SO MUCH

try

Invoiced net sales converted =
VAR SelectedCurrency =
    SELECTEDVALUE ( 'Exch rate'[Currency] )
RETURN
    IF (
        NOT ISBLANK ( SelectedCurrency ),
        SUMX (
            'Table',
            VAR ReferenceDate = 'Table'[Invoice date]
            VAR ReferenceAmount = 'Table'[Invoiced net sales]
            VAR ExchRate =
                CALCULATE (
                    MAX ( 'Exch rate'[_EXCH_RATE] ),
                    'Exch rate'[Currency] = SelectedCurrency,
                    'Exch rate'[Date] = DATE( YEAR( ReferenceDate), MONTH(ReferenceDate),1)
                )
            RETURN
                ExchRate * ReferenceAmount
        )
    )

@johnt75 ,

This is working GREAT. Thank you SO MUCH.
I want to ask for some more help. How can I use this same measure with the USERELATIONSHIP function? I have two other dates looking at different amounts in the same fact table. I did try, but it's not working for me.

THANKS AGAIN 🙂

You'd need to change the columns in the ReferenceDate and ReferenceAmount columns. If you need to be able to chart it against the different dates you might wrap the whole thing inside CALCULATE( ..., USERELATIONSHIP('Table2'[Date],'Date'[Date]))

Hi @johnt75 

Yes, I created the way you discribed.

VAR ReferenceDate = CALCULATE(VALUES('FACT'[ DATE]), USERELATIONSHIP('DIMDATE'[CalendarDate], 'FACT'[DATE]))

Its not working.

I meant something like

Using different date =
CALCULATE (
    VAR SelectedCurrency =
        SELECTEDVALUE ( 'Exch rate'[Currency] )
    RETURN
        IF (
            NOT ISBLANK ( SelectedCurrency ),
            SUMX (
                'Table',
                VAR ReferenceDate = 'Table'[Date 2]
                VAR ReferenceAmount = 'Table'[Different amount]
                VAR ExchRate =
                    CALCULATE (
                        MAX ( 'Exch rate'[_EXCH_RATE] ),
                        'Exch rate'[Currency] = SelectedCurrency,
                        'Exch rate'[Date] = DATE ( YEAR ( ReferenceDate ), MONTH ( ReferenceDate ), 1 )
                    )
                RETURN
                    ExchRate * ReferenceAmount
            )
        ),
    USERELATIONSHIP ( 'Date'[Date], 'Table'[Date 2] )
)

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