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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
konradjonsson
Helper II
Helper II

How to improve DAX query performance - aggregation of multiple currencies

Hi.

Originally I had a DAX measure that gave the correct result on row level, but totals where wrong. See bottom of message.

I had a previous solution where the iteration is at a granular level for each row and then aggregates these results. I knew it was going to be slower, but tried it anyway.

 

My question to the community is if there are any better (=faster) ways to aggregate correctly on multiple currencies?

 

Plan (Budget) SLOW =  

SUMX('Plan data', 

    VAR _recordDate = 'Plan data'[DateIntKey] 

    VAR _recordCurrency = 'Plan data'[CurrencyKey] 

    VAR _displayCurrency =

SELECTEDVALUE('Slicer - Targetcurrency'[Currency_BK]) 

    VAR _exchangeRateType = [Exchange Rate Type] 

    VAR _exchangeRate = CALCULATE( 

        MAX('FactExchangeRate'[Rate]), 

        'FactExchangeRate'[Date_SK] = _recordDate, 

        'FactExchangeRate'[FromCurrencyCode] = _recordCurrency, 

        'FactExchangeRate'[ExchangeRateType] = _exchangeRateType, 

        'FactExchangeRate'[ToCurrencyCode] = _displayCurrency 

    ) 

    VAR _valueInRecordCurrency = [Plan (Budget) LOCAL] 

 

    RETURN 

        _valueInRecordCurrency * _exchangeRate 

) 

 

 

The original DAX query - actually two.

Plan (Budget) INCORRECT TOTALS 

VAR LocalAmount = 

    CALCULATE( 

        SUM('Plan data'[Value]), 

        'Plan data'[ScenarioKey] = "EF", 

        'Plan data'[MeasureKey] = "M2" 

    ) 

 

RETURN 

    LocalAmount * [Exchange Rate] 

 

 

Exchange Rate 

VAR _date = 

    MAXX ( 'Plan data', 'Plan data'[DateIntKey] ) 

 

VAR _currency = 

    MAXX ( 

        'Plan data', 

        'Plan data'[CurrencyKey] 

    ) 

 

VAR _DisplayCurrency = 

    SELECTEDVALUE ( 'Slicer - Targetcurrency'[Currency_BK] ) 

      

VAR _exchangeratetype = [Exchange Rate Type] 

 

RETURN 

    CALCULATE ( 

        MAX ( 'FactExchangeRate'[Rate] ), 

        'FactExchangeRate'[Date_SK] = _date, 

        'FactExchangeRate'[FromCurrencyCode] = _currency, 

        'FactExchangeRate'[ExchangeRateType] = _exchangeratetype, 

        'FactExchangeRate'[ToCurrencyCode] = _displaycurrency 

    ) 

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

Hi @konradjonsson,


Try to determine if you are at the "total level" with ISINSCOPE and do the calculations separately:

Measure = IF(ISINSCOPE('financials'[Category]),[Plan (Budget) SLOW],[Plan (Budget) INCORRECT TOTALS])


ISINSCOPE – DAX Guide
The importance of star schemas in Power BI - SQLBI

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

1 REPLY 1
v-cgao-msft
Community Support
Community Support

Hi @konradjonsson,


Try to determine if you are at the "total level" with ISINSCOPE and do the calculations separately:

Measure = IF(ISINSCOPE('financials'[Category]),[Plan (Budget) SLOW],[Plan (Budget) INCORRECT TOTALS])


ISINSCOPE – DAX Guide
The importance of star schemas in Power BI - SQLBI

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.