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.
Hello Community!
I'm quite new in DAX and unfortunately came on a quite complicated case.
I have a table with exchange rates. I need to extract exchange rates for the last day of each month.
I cannot use the function that gives me the last day of the month, because sometimes the last day of the month is not the last day when the exchange rate was issued. Below is the initial table:
Bank | From | To | Date | Rate |
ECB | EUR | USD | 28.10.2019 | 23,21 |
ECB | EUR | USD | 27.10.2019 | 13,21 |
ECB | EUR | USD | 26.10.2019 | 22,21 |
ECB | EUR | USD | 25.10.2019 | 43,21 |
ECB | EUR | USD | 28.09.2019 | 53,21 |
ECB | EUR | USD | 27.09.2019 | 23,21 |
ECB | EUR | USD | 26.09.2019 | 13,21 |
ECB | EUR | USD | 28.08.2019 | 22,21 |
ECB | EUR | USD | 27.08.2019 | 43,21 |
ECB | EUR | USD | 26.08.2019 | 53,21 |
ECB | EUR | USD | 25.08.2019 | 73,21 |
ECB | EUR | USD | 24.08.2019 | 93,21 |
After the transition I'd like to have:
Bank | From | To | Date | Rate |
ECB | EUR | USD | 28.10.2019 | 23,21 |
ECB | EUR | USD | 28.09.2019 | 53,21 |
ECB | EUR | USD | 28.08.2019 | 22,21 |
Any clues Dear Masters of DAX? 😉
Solved! Go to Solution.
Column =
VAR maxDate = CALCULATE(MAX(Test[Date]),ALLEXCEPT(Test,Test[Date].[Month],Test[Date].[Year]))
RETURN CALCULATE(SUM(Test[Rate]),Test[Date]=maxDate)
@Anonymous @Anonymous
Thank you very much - both solutions work very well!
I've learned a lot here, so thank you again for this! 🙂
@Anonymous @Anonymous
Oh... I'm afraid something is not right with those formulas - both calculate the right values but just within one calendar year. I need to extract those values for the whole database that has years back data. For now, I can't get a value for e.g. 31.03.2014 - it is blank...
Any ideas on fixing this? 🙂
Column =
VAR maxDate = CALCULATE(MAX(Test[Date]),ALLEXCEPT(Test,Test[Date].[Month],Test[Date].[Year]))
RETURN CALCULATE(SUM(Test[Rate]),Test[Date]=maxDate)
I don't know exactly why it works, but it looks like it works! Thank you again!
I am dealing with a similar problem and I have fixed it using a column like this one:
Column =
VAR maxDate = CALCULATE(MAX(Test[Date]),ALLEXCEPT(Test,Test[Date].[Month]))
RETURN CALCULATE(SUM(Test[Rate]),Test[Date]=maxDate)
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 |
---|---|
41 | |
21 | |
21 | |
14 | |
13 |
User | Count |
---|---|
44 | |
32 | |
30 | |
18 | |
17 |