Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
sw123
Helper III
Helper III

Currency exchange on yearly basis

Hi,

I would like to add a column to a table that always shows the amount in euro. My table looks like this (example):

 

Yearmonth

Amount

Currency

202001

48567

EUR

202102

8762

SEK

202211

89765

USD

 

It means I have reported different amounts for each month, and the amount can be in different currencies. Can I add a column to this table, that always shows the amount in EUR according to the year? I am using the exchange currency rate on a year basis like this:

 

Year

SEK

NOK

USD

2021

10.1

10.3

1.18

2022

10.3

10.2

1.15

2023

10.8

10

1

 

Is this possible?

Thanx in advance!

1 ACCEPTED SOLUTION
Barthel
Solution Sage
Solution Sage

Hey @sw123,

I recommend that you unpivot the currency table, this makes it easier to work with. You can do this dynamically in M.

YearCurrencyValue

2021SEK10,1
2021NOK10,3
2021USD1,18
2022SEK10,3
2022NOK10,2
2022USD1,15
2023SEK10,8
2023NOK10
2023USD1

Then you can apply the following DAX calculation as a calculated column:

 

 

EUR = 
VAR _year =
    { LEFT ( 'Table'[Yearmonth], 4 ) }
VAR _currency = 
    { 'Table'[Currency] } 
VAR _rate =
    CALCULATE ( 
        SELECTEDVALUE ( 'Currency'[Value] ),
        TREATAS ( _year, 'Currency'[Year] ),
        TREATAS ( _currency, 'Currency'[Currency] )
    )
VAR _result =
    DIVIDE ( 'Table'[Amount], COALESCE ( _rate, 1 ) )
RETURN
    _result 

 

 

Everything for which no exchange rate can be found for the relevant year (in the case only for EUR), is always taken as 1 as a rate.

Barthel_0-1672659362327.png

 

View solution in original post

3 REPLIES 3
Barthel
Solution Sage
Solution Sage

Hey @sw123,

I recommend that you unpivot the currency table, this makes it easier to work with. You can do this dynamically in M.

YearCurrencyValue

2021SEK10,1
2021NOK10,3
2021USD1,18
2022SEK10,3
2022NOK10,2
2022USD1,15
2023SEK10,8
2023NOK10
2023USD1

Then you can apply the following DAX calculation as a calculated column:

 

 

EUR = 
VAR _year =
    { LEFT ( 'Table'[Yearmonth], 4 ) }
VAR _currency = 
    { 'Table'[Currency] } 
VAR _rate =
    CALCULATE ( 
        SELECTEDVALUE ( 'Currency'[Value] ),
        TREATAS ( _year, 'Currency'[Year] ),
        TREATAS ( _currency, 'Currency'[Currency] )
    )
VAR _result =
    DIVIDE ( 'Table'[Amount], COALESCE ( _rate, 1 ) )
RETURN
    _result 

 

 

Everything for which no exchange rate can be found for the relevant year (in the case only for EUR), is always taken as 1 as a rate.

Barthel_0-1672659362327.png

 

Super! Thanx!

amitchandak
Super User
Super User

@sw123 , Unpivot the second table, then you can get the rate based on join 

 

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

 

New column in power query for year in table 1

Text.Start(Number.FromText([Month Year]),4)

 

You can merge both tables. You can select more than one column using the shift

 : https://radacad.com/append-vs-merge-in-power-bi-and-power-query

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.