Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
PubliusEnigma
Frequent Visitor

Select latest dates in every month across many years data set

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:

 

BankFromToDateRate
ECBEURUSD28.10.201923,21
ECBEURUSD27.10.201913,21
ECBEURUSD26.10.201922,21
ECBEURUSD25.10.201943,21
ECBEURUSD28.09.201953,21
ECBEURUSD27.09.201923,21
ECBEURUSD26.09.201913,21
ECBEURUSD28.08.201922,21
ECBEURUSD27.08.201943,21
ECBEURUSD26.08.201953,21
ECBEURUSD25.08.201973,21
ECBEURUSD24.08.201993,21

 

After the transition I'd like to have:

 

 

BankFromToDateRate
ECBEURUSD28.10.201923,21
ECBEURUSD28.09.201953,21
ECBEURUSD28.08.201922,21

 

Any clues Dear Masters of DAX? 😉

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@PubliusEnigma 

Column = 
VAR maxDate = CALCULATE(MAX(Test[Date]),ALLEXCEPT(Test,Test[Date].[Month],Test[Date].[Year]))
RETURN  CALCULATE(SUM(Test[Rate]),Test[Date]=maxDate)

View solution in original post

6 REPLIES 6
PubliusEnigma
Frequent Visitor

@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? 🙂

Anonymous
Not applicable

@PubliusEnigma 

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!

Anonymous
Not applicable

Hi @PubliusEnigma 

 

I am dealing with a similar problem and I have fixed it using a column like this one:

 

last_Rate = IF(CALCULATE(MAX ('Table_Name'[Date]); ALLEXCEPT(Table_Name;Table_Name[month_date]))=Table_Name[Date];Table_Name[Rate];BLANK())
Anonymous
Not applicable

Column = 
VAR maxDate = CALCULATE(MAX(Test[Date]),ALLEXCEPT(Test,Test[Date].[Month]))
RETURN  CALCULATE(SUM(Test[Rate]),Test[Date]=maxDate)

@PubliusEnigma

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors