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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
officeiq
Helper I
Helper I

Get the last day of the prior year in m query

I need to add a column to my table that will be the last day of the prior year (e.g. Dec 31, Prior Year/ Dec 31, 2023) so I can build logic that can evaluate the results of this column vs another date column. For example, if Creation Date column is greater than or equal to Prior Date then Y, else N. Then can filter the table by Y or N.

 

I currently am going in and updating that column manually, but would like a to know if anyone has creted/knows of a way in M Query to generate that Prior Date with a function so i do not have to do it every year manually.

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@officeiq 

Suppose you have a date column called Date, add a custom column with this code:

Date.AddYears(Date.EndOfYear([Date]),-1)

Fowmy_0-1705264849765.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

Thanks for your suggestion - I used it with one small modification - I added a column called Today, which uses DateTime.Date(DateTime.LocalNow())) for the column data, so it will automatically update each year. So your updated solution is Date.AddYears(Date.EndOfYear([Today]),-1)) = Thanks

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@officeiq 

Suppose you have a date column called Date, add a custom column with this code:

Date.AddYears(Date.EndOfYear([Date]),-1)

Fowmy_0-1705264849765.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thanks for your suggestion - I used it with one small modification - I added a column called Today, which uses DateTime.Date(DateTime.LocalNow())) for the column data, so it will automatically update each year. So your updated solution is Date.AddYears(Date.EndOfYear([Today]),-1)) = Thanks

Helpful resources

Announcements
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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.