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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Voose
Helper III
Helper III

Date function not working as intended?

Hi All,

 

I have an interesting conundrum, this formula works across all dates in the calendar year upto the July 2018 from 2015, however there is one date it doesn't work for. 

 

For the below formula the Close date review field = 31 March 2018

The Formula should return the value = 30 June 2018

Current returned value is = 1 July 2018

 

Timing Risk Review Date = if(Opportunity[Forecast_Review__c] = "Upside - Timing Risk",DATE(YEAR(Opportunity[close date review].[Date]),MONTH(Opportunity[close date review])+3,DAY(Opportunity[close date review].[Date])),Opportunity[close date review].[Date])

 

The intention of this formula is to simply add 3 months to a date whilst ignoring days / years.

 

Let me know what you think guys

 

Thanks

 

Voose

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

Perhaps use DATEADD instead?

 

https://msdn.microsoft.com/en-us/library/ee634905.aspx

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

AlbertoFerrari
Most Valuable Professional
Most Valuable Professional

Well, DATEADD should work just fine, I have never seen a bug with that functions, and it should be the way to go.

 

If, on the other hand, you want to do it manually, then you can follow a simple technique. Create a Y12M column in the Date table that contains (Year * 12 + Month). With that column in place, you can freely move back and forth with months by adding to that value the offset.

 

So, MAX ( Date[Y12M] - 3 ) results in three months ago, no matter which year you are into.

 

But, if I were you, I would try to understand what's wrong with DATEADD, as this is the best way of expressing date offsets.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

View solution in original post

8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

Perhaps use DATEADD instead?

 

https://msdn.microsoft.com/en-us/library/ee634905.aspx

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hello Smoupre!

 

Initially I started out using the Dataadd function but that didn't give the desired result, it basically added months when I wanted which was good but seemingly randomly it just returned blank for 4 dates (there are about 5k dates in this table) and I couldn't find any comminality between those 4 so I switched to this method instead 😞

 

Thanks

 

Voose

 

 

Microsoft's information on the DATE function, clearly explains what happens if you supply a day number > last day of the month (and lots of other information as well)

Specializing in Power Query Formula Language (M)

Hi Marcelbeug,

 

I think you may have misread the formula, I'm not adding days... I'm adding months and the place you've linked would be useful if I were adding more months or days than there are in a given month of day however I am not I am adding 3 Months in a particular scenario.

 

Thanks

 

Voose

AlbertoFerrari
Most Valuable Professional
Most Valuable Professional

Well, DATEADD should work just fine, I have never seen a bug with that functions, and it should be the way to go.

 

If, on the other hand, you want to do it manually, then you can follow a simple technique. Create a Y12M column in the Date table that contains (Year * 12 + Month). With that column in place, you can freely move back and forth with months by adding to that value the offset.

 

So, MAX ( Date[Y12M] - 3 ) results in three months ago, no matter which year you are into.

 

But, if I were you, I would try to understand what's wrong with DATEADD, as this is the best way of expressing date offsets.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

@AlbertoFerrari - I feel like I've just had a celebrity reply to my post! Smiley Embarassed

 

Even more embarrsing, I left my original test of the DateAdd function in my model and I've just gone back to look at it and all of the dates seem to be filled in.... the only difference I can see is in the data type being Date and not Date time, that being said switching it back doesn't seem to effect it.

 

On an aside, please come to england for more talks 🙂

 

Thanks

 

Voose

MarcelBeug
Community Champion
Community Champion

If you add 3 months to DATE(2018,3,31) then you end up in DATE(2018,6,31), which returns July 1, 2018, because June has only 30 days. I don't think I misread anything.

Specializing in Power Query Formula Language (M)

@MarcelBeug I see, that does make sense... 

 

Cheers

 

Voose

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors