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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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 Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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