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.
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 -
CompanyCode | DocumentNo | Currency | SalesAmount |
100 | 1001 | EUR | 100 |
100 | 1002 | EUR | 200 |
100 | 1003 | CAD | 100 |
100 | 1004 | CAD | 400 |
Exchange Rate -
Currency | -->USD Rate |
EUR | 1.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.
Step 1-
CompanyCode | Currency | SalesAmount |
100 | EUR | 300 |
100 | CAD | 500 |
Step 2-
CompanyCode | Currency | SalesAmount | Rate | Amount |
100 | EUR | 300 | 1.2 | 360 |
100 | CAD | 500 | .77 | 385 |
Result -
CompanyCode | Amount |
100 | 745 |
Please advise the DAX to achive this. Thank you in advance!
Solved! Go to Solution.
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] )
)
)
Then try this measure:
Amount = SUMX(DISTINCT('Table'[Currency]),CALCULATE(MAX('Table'[Sales])*MAX('Table'[Rate])))
The result shows:
Here is my test pbix file:
Hope this helps.
Best Regards,
Giotto Zhi
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] )
)
)
Then try this measure:
Amount = SUMX(DISTINCT('Table'[Currency]),CALCULATE(MAX('Table'[Sales])*MAX('Table'[Rate])))
The result shows:
Here is my test pbix file:
Hope this helps.
Best Regards,
Giotto Zhi
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |