cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mboucher_rcr
Frequent Visitor

Max Date in Data from 12 Months Ago

Hi,

 

I have a measure that gives me the last date of available data that is then used in other measures:

Last date of data availability = MAX(ItemSales[WkStartDate])
 
What I need to do is get the same thing but for 12 months earlier. I don't want the same date minus 12 months, I still need a valid [WkStartDate] from my data but from 12 months earlier.
 
For example if my MAX(ItemSales[WkStartDate]) = 27th June 2022
I don't just want 27th June 2021, as that date doesn't exist as a [WkStartDate] value in my data. In my case, the dates are always a Monday, so I would expect to get 21st June 2021 as that's the highest date available when you take 12 months off the 27th June 2022.
 
Can anyone please help?
 
Thanks,
Michael
2 REPLIES 2
amitchandak
Super User
Super User

@mboucher_rcr , try like

 

new measure =
var _max1 = MAX(ItemSales[WkStartDate])
var _max = date(year(_max1)-1, Month(_max1) , Day(_max1))
return
maxx(filter(Allselected(ItemSales), ItemSales[WkStartDate] <=_max) , ItemSales[WkStartDate])



Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Learn Power BI P&L Statement || Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s ||
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!

Hi,

Thanks for that. I've just tried it and am getting this error: A single value for column 'WkStartDate' in table 'ItemSales' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum...

 

Thanks,
Michael

Helpful resources

Announcements
November 2022 Update

Check it Out!

Click here to read more about the November 2022 updates!

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.