cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dkpcr5
Helper I
Helper I

M Query - January 1st of Previous Year

Hi all,

I'm looking for an M Query assist.

I'd like to set my StartDate to January 1st of the previous year, and my EndDate to the current day. So, start date should read 01-01-2020 and EndDate should read (today, so 09-23-2021). How would I cast that in M Query?

 

let StartDate = ...?

let EndDate = Date.From(DateTime.LocalNow()) ...?

 

Thank you!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@dkpcr5 

let EndDate = Date.From(DateTime.LocalNow())
let StartDate = #date(Date.Year(EndDate)-1,1,1)

@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

Another way would be to use the Date.StartOfYear and Date.AddYears functions.

 

StartDate = Date.From(Date.StartOfYear(Date.AddYears(DateTime.LocalNow(), -1)))

Greg_Deckler
Super User
Super User

@dkpcr5 

let EndDate = Date.From(DateTime.LocalNow())
let StartDate = #date(Date.Year(EndDate)-1,1,1)

@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors