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
CliffordAP
Helper II
Helper II

Calculate same day previous month DAX

Hello everyone!

     I think my inquiry should be an easy one.

I want to find a way to compute a date based on the output of another date.

Say I have the following date,

     DATE(2021,01,16)
I want to simply adjust this date to the same day of the previous month such that it has the following output;

     DATE(2020,12,16)

Apparently PREVIOUSMONTH(DATE(2021,01,16)) does not work.

Any ideas?

4 REPLIES 4
Anonymous
Not applicable

Hello @CliffordAP 
You can use dateadd .
LastMonth = DATEADD('Table'[Date], -1, Month) 

CliffordAP
Helper II
Helper II

NVM!
I figured it out. There is a simple way to do this.

 

You can use the MONTH function to calculate the previous month of the output date, and subtract the number of months.

 

DATE(2021,MONTH(DATE(2021,01,16))-1,16)

output

DATE(2020,12,16). 🙂

Anonymous
Not applicable

@CliffordAP 

 

No, this is a very bad way to handle time calculations. Please read this and do not make mistakes others so easily do: Time Intelligence in Power BI Desktop - SQLBI

Looks good but watch out for the 31st. How do you want to handle those?

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.

Top Solution Authors