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
Anonymous
Not applicable

SUMX - Currency Conversion

Hi,

We have a requirement to calculate the currency conversion and the DAX that is being used is simple - 

Sales Amount = SUMX (Sales, Sales[SalesAmt]*CALCULATE ( SUM ( ExchangeRate[ExchRate] ), USERELATIONSHIP ( Sales[Currency], ExchangeRate[Currency] ) )) 

 

This is working fine when using on small data sets but when it has to loop through millions of records it giving a memory error as it has to hold large volume of data in the memory. 

 

Sales Transactions -

CompanyCodeDocumentNoCurrencySalesAmount
1001001EUR100
1001002EUR200
1001003CAD100
1001004CAD400

 

Exchange Rate - 

Currency -->USD Rate
EUR1.2
CAD.77

 

In the above example, there are 4 transactions and looping thorugh all those records is impacting the performance.

If we can apply the processing as below, I think we can aviod SUMX altogether. 

  1. Use SUM or some other function and summarize the data at the currency code level/ granularity - 2 records ( 2 currencies - CAD & EUR ).
  2. Apply the rate for those 2 records.

 

Step 1- 

CompanyCodeCurrencySalesAmount
100EUR300
100CAD500

 

Step 2-

CompanyCodeCurrencySalesAmountRateAmount
100EUR3001.2360
100CAD500.77385

 

Result -

CompanyCodeAmount
100745

 

Please advise the DAX to achive this. Thank you in advance!

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

Hi,

 

Pleaase try to create this calculated table:

Table = 
ADDCOLUMNS (
    SUMMARIZE (
        'Sales Transactions',
        'Sales Transactions'[CompanyCode],
        'Sales Transactions'[Currency],
        "Sales", SUM ( 'Sales Transactions'[SalesAmount] )
    ),
    "Rate", CALCULATE (
        SUM ( 'Exchange Rate'[ -->USD Rate] ),
        USERELATIONSHIP ( 'Sales Transactions'[Currency], 'Exchange Rate'[Currency] )
    )
)

20.PNG

Then try this measure:

Amount = SUMX(DISTINCT('Table'[Currency]),CALCULATE(MAX('Table'[Sales])*MAX('Table'[Rate])))

The result shows:

21.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

View solution in original post

2 REPLIES 2
v-gizhi-msft
Community Support
Community Support

Hi,

 

Pleaase try to create this calculated table:

Table = 
ADDCOLUMNS (
    SUMMARIZE (
        'Sales Transactions',
        'Sales Transactions'[CompanyCode],
        'Sales Transactions'[Currency],
        "Sales", SUM ( 'Sales Transactions'[SalesAmount] )
    ),
    "Rate", CALCULATE (
        SUM ( 'Exchange Rate'[ -->USD Rate] ),
        USERELATIONSHIP ( 'Sales Transactions'[Currency], 'Exchange Rate'[Currency] )
    )
)

20.PNG

Then try this measure:

Amount = SUMX(DISTINCT('Table'[Currency]),CALCULATE(MAX('Table'[Sales])*MAX('Table'[Rate])))

The result shows:

21.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

Anonymous
Not applicable

Bumping up...

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.