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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Pigbag1962
Frequent Visitor

Measure to Get Previous Years date as a Year

Hi

 

I am trying to get the previous year in YYYY format based on the last date in rolling stock table.

 

I have managed to get there but it has taken me 3 measures. Is there a way to amalgamte these into one measure or is there a better alternative?

 

Measure 1 gets the last date in table

LastDate = LASTDATE('Rolling Livestock Data'[Create dte])
 
Measure 2 gets the date 1 year earlier based on measure 1
LastYearDate = DATEADD(LASTDATE('Rolling Livestock Data'[Create dte]),-1,YEAR)
 
Measure 3 uses Year function to contract measure 2 output to YYYY
LY Year = year([LastYearDate])
 
Cheers
 
Damon
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Pigbag1962 , change the second one like

 

LastYearDate =

var _1 = LASTDATE('Rolling Livestock Data'[Create dte])

return

date(year(_1) -1, month(_1), day(_1))

View solution in original post

2 REPLIES 2
Pigbag1962
Frequent Visitor

Thank you for that, gives me more insight as to how to use DAX.

 

amitchandak
Super User
Super User

@Pigbag1962 , change the second one like

 

LastYearDate =

var _1 = LASTDATE('Rolling Livestock Data'[Create dte])

return

date(year(_1) -1, month(_1), day(_1))

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.