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
Fro88er
Helper IV
Helper IV

Apply Exchange Rates to Local Currency button

I have request to add a simple Currency Button (Local/USD). When USD is selected it applies the respected currency rate.  I have built a Currency Table (disconnected). The Temp Revenue (selected currency) meaure works, however it is appying the CAD currency rate accross all of the regions not just Toronto. There is a currency ID on the Fact Table, call it USD and CAD or Currency ID, 1 and 2). Basicly, two field buttons [Local] no filter, [USD] apply currency rates.

 

Q: How to write this measure?

 

Temp Revenue (local) =
CALCULATE(
SUM('Fact1Staff Consolidated GP'[Temp Bill Amount]))
 
Temp Revenue (selected currency) =
SWITCH(TRUE(),
[Selected Currency]="CAD", [Temp Revenue (local)]*VALUES(DimCurrency[Currency Rate]),
[Temp Revenue (local)])
 
CurrencyToggleCurrency.JPGCurrencyToggleCAD.JPG
1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Fro88er ,

Please update the formula of measure as below:

Temp Revenue (selected currency) = 
VAR _selcurrency =
    SELECTEDVALUE ( 'DimCurrency'[Currency] )
VAR _currate =
    CALCULATE (
        MAX ( 'DimCurrency'[Currency Rate] ),
        'DimCurrency'[Currency] = _selcurrency
    )
RETURN
    IF (
        _selcurrency = "CAD"
            && MAX ( 'Fact1Staff Consolidated GP'[Region] ) = "Toronto",
        [Temp Revenue (local)] * _currate,
        [Temp Revenue (local)]
    )

Apply Exchange Rates to Local Currency button.JPG

Best Regards

Rena

Community Support Team _ Rena
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

8 REPLIES 8
v-yiruan-msft
Community Support
Community Support

Hi @Fro88er ,

Please update the formula of measure as below:

Temp Revenue (selected currency) = 
VAR _selcurrency =
    SELECTEDVALUE ( 'DimCurrency'[Currency] )
VAR _currate =
    CALCULATE (
        MAX ( 'DimCurrency'[Currency Rate] ),
        'DimCurrency'[Currency] = _selcurrency
    )
RETURN
    IF (
        _selcurrency = "CAD"
            && MAX ( 'Fact1Staff Consolidated GP'[Region] ) = "Toronto",
        [Temp Revenue (local)] * _currate,
        [Temp Revenue (local)]
    )

Apply Exchange Rates to Local Currency button.JPG

Best Regards

Rena

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

Rena,

 

After closer examination the totals do not add up. Additionally, is there a solution that does not reference the Region and just let the CurrencyID drive the logic? The reason, I also have an By Office, By Practice, tables, plus if we add another CAD city/region I have to modify the code.

Yes, this worked perfectly! I will rename my buttons to better reflect what is going on!  Thank you so much, the timing could not be better! 

Greg_Deckler
Super User
Super User

@Fro88er - I had to read this through a few times. Sample data would have helped to make this clearer. However, if I understand correctly, you want to implement a currency conversion for non-US cities. If that is the case you could do this:

Temp Revenue (selected currency) =
  VAR __SelectedCurrency = [Selected Currency]
  VAR __CityCurrency = MAX('Fact1StaffConsolidatedGP'[CurrencyID])
  VAR __Rate = MAX('Currency Table'[Currency Rate])
RETURN
  IF(__SelectedCurrency = __CityCurrency,[Temp Revenue (local)]*__Rate,[Temp Revenue (local)])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

I am have the meaure working with the variable [Temp Revenue (selected currency)] but the total do not match.  When I write a seperate measure [Temp Revenue Test] the numbers and totals match. However, when I try and add/merge into only 1 measure, the [Temp Revenue (selected currency)] that includes the variables with a Sumx function the totals don't match either, what am I doing wrong?

 

Temp Revenue (selected currency) =
VAR __SelectedCurrency = 2
VAR __CityCurrency = MAX('Fact1Staff Consolidated GP'[ExchangeRateID])
VAR __Rate = MAX(DimCurrency[Currency Rate])
RETURN
IF(__SelectedCurrency = __CityCurrency,[Temp Revenue (local)]*__Rate,[Temp Revenue (local)])

 

Temp Revenue Test =
SUMX(
'Fact1Staff Consolidated GP',[Temp Revenue (selected currency)])

 

 

xTemp Revenue (Selected Currency)GD 2 =
VAR __SelectedCurrency = 2
VAR __CityCurrency = MAX('Fact1Staff Consolidated GP'[ExchangeRateID])
VAR __Rate = MAX(DimCurrency[Currency Rate])
Var VarTotal = IF(__SelectedCurrency = __CityCurrency,[Temp Revenue (local)]*__Rate,[Temp Revenue (local)])
Var VarTable = SUMMARIZE('Fact1Staff Consolidated GP','Fact1Staff Consolidated GP'[1Staff Office.Region],"RegionTempRevenue",VarTotal)
RETURN
SUMX(VarTable,VarTotal)
 
CurrencyToggleCurrency4.JPG

@Fro88er This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

Sorry I lost track of this, I don't check my messages on this site very often!!



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

lbendlin
Super User
Super User

Your SWITCH() statement needs to test for Toronto, not for CAD.

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.