Forum Discussion
Dax Help
Good Afternoon. I'm fairly new to using DAX so bear with me. I'm trying to use DAX to calculate invoice amounts in different currencies. I have two example tables below in my PBI desktop. These tables are joined by the cruno field in the data model. The correct rate to apply to the inv_amt_usd is a function of the cruno field and the currency code (which a user would select from a slicer with the currency codes). I want to add a measure that would calculate the different currency invoice amount for each invoice so I can add the information in the invoice table to a table visual along with the correct billed amount given the selected currency. Any Ideas?
- Anonymous1 year ago
Hi hoopaz68 ,
In the data you provided, the cruno field does not have a unique identifier and cannot be used as a condition for joining tables.
But based on your requirement, you can refer to the following formula:SelectedCurrencyRate = CALCULATE ( MAX ( 'Currency_Table'[rate] ), FILTER ( 'Currency_Table', 'Currency_Table'[cruno] = SELECTEDVALUE ( 'Invoice Table'[cruno] ) && 'Currency_Table'[currency] = SELECTEDVALUE ( 'Currency_Table'[currency] ) ) )ConvertedInvoiceAmount = SUMX( 'Invoice Table', 'Invoice Table'[inv_amt_usd] * [SelectedCurrencyRate] )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
8 Replies
- Ashish_MathurSuper User
Hi,
Share data in a format that can be pasted in an MS Excel file and show the expected result very clearly.
- hoopaz68New Member
Here is the data for the tables and expected results:
Currency_Tablerow_uno cruno date currency rate 1 100 9/1/2024 USD 1 2 100 9/1/2024 GBP 1.5161 3 100 9/1/2024 EUR 1.8946 4 101 9/2/2024 USD 1 5 101 9/2/2024 GBP 1.5475 6 101 9/2/2024 EUR 1.9116 7 102 9/3/2024 USD 1 8 102 9/3/2024 GBP 1.5421 9 102 9/3/2024 EUR 1.9177 Invoice Tablerow_uno cruno inv_num inv_date inv_amt_usd 1 100 4001 9/1/2024 5000 2 100 4002 9/1/2024 8700 3 101 4003 9/2/2024 2300 4 102 4004 9/3/2024 1500 5 102 4005 9/3/2024 10000 Results row_uno cruno inv_num inv_date inv_amt_usd currency rate inv_amt_converted 1 100 4001 9/1/2024 5,000.00 USD 1.0000 5,000.00 1 100 4001 9/1/2024 5,000.00 GBP 1.5161 7,580.50 1 100 4001 9/1/2024 5,000.00 EUR 1.8946 9,473.00 2 100 4002 9/1/2024 8,700.00 USD 1.0000 8,700.00 2 100 4002 9/1/2024 8,700.00 GBP 1.5161 13,190.07 2 100 4002 9/1/2024 8,700.00 EUR 1.8946 16,483.02 3 101 4003 9/2/2024 2,300.00 USD 1.0000 2,300.00 3 101 4003 9/2/2024 2,300.00 GBP 1.5475 3,559.25 3 101 4003 9/2/2024 2,300.00 EUR 1.9116 4,396.68 4 102 4004 9/3/2024 1,500.00 USD 1.0000 1,500.00 4 102 4004 9/3/2024 1,500.00 GBP 1.5421 2,313.15 4 102 4004 9/3/2024 1,500.00 EUR 1.9177 2,876.55 5 102 4005 9/3/2024 10,000.00 USD 1.0000 10,000.00 5 102 4005 9/3/2024 10,000.00 GBP 1.5421 15,421.00 5 102 4005 9/3/2024 10,000.00 EUR 1.9177 19,177.00
- danextianSuper User
Hi hoopaz68
This is just based on the image provided. Haven't tested as no workable data was provided.
USD Converted Measure = SUMX ( ADDCOLUMNS ( SUMMARIZE ( invoice_table, invoice_table[cruno], invoice_table[inv_num], invoice_table[inv_date], invoice_table[inv_amt_usd] ), "@Converted", CALCULATE ( Currency_Table[rate], FILTER ( Currency_Table, Currency_Table[cruno] = [cruno] && Currency_Table[inv_date] = [inv_date] ) ) * [inv_amt_usd] ), [@Converted] ) - AnonymousNot applicable
Hi hoopaz68 ,
Did danextian reply solve your problem? If so, please mark it as the correct solution, and point out if the problem persists.
Best regards,
Adamk Kong
- hoopaz68New Member
Not quite. I shared data and expected results for this for danextian. Thanks.
- hoopaz68New Member
Thank you for this but this didn't quite work. Here is the data for the tables and expected results:
Currency_Tablerow_uno cruno date currency rate 1 100 9/1/2024 USD 1 2 100 9/1/2024 GBP 1.5161 3 100 9/1/2024 EUR 1.8946 4 101 9/2/2024 USD 1 5 101 9/2/2024 GBP 1.5475 6 101 9/2/2024 EUR 1.9116 7 102 9/3/2024 USD 1 8 102 9/3/2024 GBP 1.5421 9 102 9/3/2024 EUR 1.9177 Invoice Tablerow_uno cruno inv_num inv_date inv_amt_usd 1 100 4001 9/1/2024 5000 2 100 4002 9/1/2024 8700 3 101 4003 9/2/2024 2300 4 102 4004 9/3/2024 1500 5 102 4005 9/3/2024 10000 Results row_uno cruno inv_num inv_date inv_amt_usd currency rate inv_amt_converted 1 100 4001 9/1/2024 5,000.00 USD 1.0000 5,000.00 1 100 4001 9/1/2024 5,000.00 GBP 1.5161 7,580.50 1 100 4001 9/1/2024 5,000.00 EUR 1.8946 9,473.00 2 100 4002 9/1/2024 8,700.00 USD 1.0000 8,700.00 2 100 4002 9/1/2024 8,700.00 GBP 1.5161 13,190.07 2 100 4002 9/1/2024 8,700.00 EUR 1.8946 16,483.02 3 101 4003 9/2/2024 2,300.00 USD 1.0000 2,300.00 3 101 4003 9/2/2024 2,300.00 GBP 1.5475 3,559.25 3 101 4003 9/2/2024 2,300.00 EUR 1.9116 4,396.68 4 102 4004 9/3/2024 1,500.00 USD 1.0000 1,500.00 4 102 4004 9/3/2024 1,500.00 GBP 1.5421 2,313.15 4 102 4004 9/3/2024 1,500.00 EUR 1.9177 2,876.55 5 102 4005 9/3/2024 10,000.00 USD 1.0000 10,000.00 5 102 4005 9/3/2024 10,000.00 GBP 1.5421 15,421.00 5 102 4005 9/3/2024 10,000.00 EUR 1.9177 19,177.00 - hoopaz68New Member
Thank you for this help. This didn't quite work. Here is the data for the tables and expected results:
Currency_Tablerow_uno cruno date currency rate 1 100 9/1/2024 USD 1 2 100 9/1/2024 GBP 1.5161 3 100 9/1/2024 EUR 1.8946 4 101 9/2/2024 USD 1 5 101 9/2/2024 GBP 1.5475 6 101 9/2/2024 EUR 1.9116 7 102 9/3/2024 USD 1 8 102 9/3/2024 GBP 1.5421 9 102 9/3/2024 EUR 1.9177 Invoice Tablerow_uno cruno inv_num inv_date inv_amt_usd 1 100 4001 9/1/2024 5000 2 100 4002 9/1/2024 8700 3 101 4003 9/2/2024 2300 4 102 4004 9/3/2024 1500 5 102 4005 9/3/2024 10000 Results row_uno cruno inv_num inv_date inv_amt_usd currency rate inv_amt_converted 1 100 4001 9/1/2024 5,000.00 USD 1.0000 5,000.00 1 100 4001 9/1/2024 5,000.00 GBP 1.5161 7,580.50 1 100 4001 9/1/2024 5,000.00 EUR 1.8946 9,473.00 2 100 4002 9/1/2024 8,700.00 USD 1.0000 8,700.00 2 100 4002 9/1/2024 8,700.00 GBP 1.5161 13,190.07 2 100 4002 9/1/2024 8,700.00 EUR 1.8946 16,483.02 3 101 4003 9/2/2024 2,300.00 USD 1.0000 2,300.00 3 101 4003 9/2/2024 2,300.00 GBP 1.5475 3,559.25 3 101 4003 9/2/2024 2,300.00 EUR 1.9116 4,396.68 4 102 4004 9/3/2024 1,500.00 USD 1.0000 1,500.00 4 102 4004 9/3/2024 1,500.00 GBP 1.5421 2,313.15 4 102 4004 9/3/2024 1,500.00 EUR 1.9177 2,876.55 5 102 4005 9/3/2024 10,000.00 USD 1.0000 10,000.00 5 102 4005 9/3/2024 10,000.00 GBP 1.5421 15,421.00 5 102 4005 9/3/2024 10,000.00 EUR 1.9177 19,177.00 - AnonymousNot applicable
Hi hoopaz68 ,
In the data you provided, the cruno field does not have a unique identifier and cannot be used as a condition for joining tables.
But based on your requirement, you can refer to the following formula:SelectedCurrencyRate = CALCULATE ( MAX ( 'Currency_Table'[rate] ), FILTER ( 'Currency_Table', 'Currency_Table'[cruno] = SELECTEDVALUE ( 'Invoice Table'[cruno] ) && 'Currency_Table'[currency] = SELECTEDVALUE ( 'Currency_Table'[currency] ) ) )ConvertedInvoiceAmount = SUMX( 'Invoice Table', 'Invoice Table'[inv_amt_usd] * [SelectedCurrencyRate] )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.