Forum Discussion
Exchange Rate Conversion with Date Selection (Slicer)
- 2 years ago
OK, you asked for it 🙂 I have updated the .pbix file in my shared Google Drive. No need to link your Calendar table to Sales table. Here's the updated DAX measure to calculate sales in USD from currencies you have in the Sales table.
Google Drive link: https://drive.google.com/drive/folders/1v0nMgmbXVJLINH-56930In51WaBQrmvJ?usp=sharing
Sales (USD) =VAR SelectedStartDate = MIN(Calendar[Date])VAR SelectedEndDate = MAX(Calendar[Date])VAR AvgExchangeRateCAD = CALCULATE(AVERAGE('XE Rates'[CAD]), 'XE Rates'[Date] >= SelectedStartDate, 'XE Rates'[Date] <= SelectedEndDate)VAR AvgExchangeRateEUR = CALCULATE(AVERAGE('XE Rates'[EUR]), 'XE Rates'[Date] >= SelectedStartDate, 'XE Rates'[Date] <= SelectedEndDate)VAR AvgExchangeRateCHF = CALCULATE(AVERAGE('XE Rates'[CHF]), 'XE Rates'[Date] >= SelectedStartDate, 'XE Rates'[Date] <= SelectedEndDate)RETURNIF(HASONEVALUE(Sales[Currency]),SWITCH(SELECTEDVALUE(Sales[Currency]),"CAD", [Total Sales] / AvgExchangeRateCAD,"EUR", [Total Sales] / AvgExchangeRateEUR,"CHF", [Total Sales] / AvgExchangeRateCHF,"USD", [Total Sales],BLANK()),SUMX(VALUES(Sales[Currency]),VAR CurrentCurrency = Sales[Currency]VAR CurrentSales = CALCULATE([Total Sales], Sales[Currency] = CurrentCurrency)RETURNSWITCH(CurrentCurrency,"CAD", CurrentSales / AvgExchangeRateCAD,"EUR", CurrentSales / AvgExchangeRateEUR,"CHF", CurrentSales / AvgExchangeRateCHF,"USD", CurrentSales,BLANK())))
Hi PBI-Enthusiast Look at the solution in my Google Drive.
https://drive.google.com/drive/folders/1v0nMgmbXVJLINH-56930In51WaBQrmvJ?usp=sharing
If I answered your question, please mark this thread as accepted and Thums Up!
Follow me on LinkedIn:
https://www.linkedin.com/in/mustafa-ali-70133451/
Hi amustafa
Thank you for the suggested solution.
In general that would work, but I don't have any date column in my Sales table which is relevant in this case. The column from table ExchangeRate[ExchangeDate] is only related to the Calendar[Date]. I could also use ExchangeRate[ExchangeDate] in my date slicer directly, which would eliminate the Calendar table to make the model less complex.
I tried to replace this line:
VAR SaleDate = Sales[Sales Date]
VAR SaleDate = MAX('Calendar'[Date])
Maybe one solution would be to redesign my data model, but I don't know how it should look like.