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
DimaMD
Solution Sage
Solution Sage

Calculate Exchange rate for every day "USD"

Hello community!

 

In previous post we had an issue that we needed to fill empty cell with exhange rate from cells of the closest calendar data. 

@smpa01 helped us to solve this task here 

But now I need to make some more calculations, and for that purpose we need to make a collum which will display all cells in USD. We need to multiply mesure M2 with USD currency, so we made a collum with USD currency, but the problem is when we have a row in table, that displays EUR, PLN etc, the cell stays empty. We need to fill all empty cells, no matter what currency was in a row, with USD
Screenshot_3.jpgScreenshot_4.jpg

Files example


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
1 ACCEPTED SOLUTION

@DimaMD  try out this measure along the same line as the previous one

Measure4 = 
VAR _0 =
    ADDCOLUMNS ( Costs, "newCurrency", "USD" )
VAR _2 =
    ADDCOLUMNS (
        _0,
        "dt2",
            VAR dt =
                CALCULATE (
                    CALCULATE (
                        MAX ( 'Exchange rate'[Date] ),
                        TREATAS (
                            SUMMARIZE ( _0, [Date], [newCurrency] ),
                            'Exchange rate'[Date],
                            'Exchange rate'[Currency]
                        )
                    )
                )
            RETURN
                IF (
                    dt = BLANK (),
                    MAXX (
                        FILTER (
                            'Exchange rate',
                            'Exchange rate'[Currency] = EARLIER ( [newCurrency] )
                                && 'Exchange rate'[Date] <= EARLIER ( [Date] )
                        ),
                        'Exchange rate'[Date]
                    ),
                    dt
                )
    )
VAR _3 =
    ADDCOLUMNS (
        _2,
        "val",
            MAXX (
                FILTER (
                    'Exchange rate',
                    'Exchange rate'[Currency] = EARLIER ( [newCurrency] )
                        && 'Exchange rate'[Date] = EARLIER ( [dt2] )
                ),
                'Exchange rate'[Exchange rate]
            )
    )
RETURN
    SUMX ( _3, [val] * [Costs] )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

6 REPLIES 6
DimaMD
Solution Sage
Solution Sage

@smpa01 
I managed to find a solution on my own
I unscrewed the table of exchange rates "USD"
Screenshot_7.jpg
then created a column in which the exchange rate for the previous day is returned
Screenshot_7.jpg

and so I got the desired result
Screenshot_9.jpg
I hope it will be useful for someone, what is your opinion @smpa01 


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

@DimaMD  try out this measure along the same line as the previous one

Measure4 = 
VAR _0 =
    ADDCOLUMNS ( Costs, "newCurrency", "USD" )
VAR _2 =
    ADDCOLUMNS (
        _0,
        "dt2",
            VAR dt =
                CALCULATE (
                    CALCULATE (
                        MAX ( 'Exchange rate'[Date] ),
                        TREATAS (
                            SUMMARIZE ( _0, [Date], [newCurrency] ),
                            'Exchange rate'[Date],
                            'Exchange rate'[Currency]
                        )
                    )
                )
            RETURN
                IF (
                    dt = BLANK (),
                    MAXX (
                        FILTER (
                            'Exchange rate',
                            'Exchange rate'[Currency] = EARLIER ( [newCurrency] )
                                && 'Exchange rate'[Date] <= EARLIER ( [Date] )
                        ),
                        'Exchange rate'[Date]
                    ),
                    dt
                )
    )
VAR _3 =
    ADDCOLUMNS (
        _2,
        "val",
            MAXX (
                FILTER (
                    'Exchange rate',
                    'Exchange rate'[Currency] = EARLIER ( [newCurrency] )
                        && 'Exchange rate'[Date] = EARLIER ( [dt2] )
                ),
                'Exchange rate'[Exchange rate]
            )
    )
RETURN
    SUMX ( _3, [val] * [Costs] )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi, @smpa01 

so this is also a great solution, I prefer to describe measure. my experience in dax is still small there is still something to learn


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

@DimaMD  I did not have time at all to look into it; will update you once I get a chance.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
smpa01
Super User
Super User

@DimaMD  to confirm, what I provided you previously, it should only do the calculation for "USD" only, meaning if the cell value is USD then do the calculation accordingly otherwise overwrite any other currecny as "USD" and do the calculation? Please confirm

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Yes, correct. If the row have other currency, we need to overwrite it as closest “up to date” "USD" and do the calculation.


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

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