The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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)
User | Count |
---|---|
16 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
12 | |
8 | |
8 |