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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Previous Month from a Date Column in Query Editor

So I have to do this in Query Editor. I have a date column that has various dates like 2/1/16, 3/3/16, 4/2/16, etc.. I need to create a column with a date that is the last day of the previous month based on this date column. So the result from the previous dates would be 1/31/16, 2/29/16, 3/31/16, etc. 

 

Not very familiar with M Code so I'm unsure how to do this. I can't just subtract one day since the date column could be the second or third day or so into the next month. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous,

You can add a custom column and paste in the following code:

=Date.EndOfMonth(Date.AddMonths(DateColumn, -1))

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@Anonymous,

You can add a custom column and paste in the following code:

=Date.EndOfMonth(Date.AddMonths(DateColumn, -1))

Easy and nice, no techincal debt

Anonymous
Not applicable

@Anonymous Easy enough! Thanks for the help!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.