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
Keiser
Frequent Visitor

DateAdd issue

Hello I have a set of dates that I want to add 1 years too, Here is the Dax

 

Keiser_0-1646154923002.png

 

Iit works fine untill I get to 2023 See below

 

Keiser_1-1646155088835.png

Any Ideas?

 

 

 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi  @Keiser ,

 

Agree with @edhans , please use EDATE() to add years.

Or you could use Date.AddYears() to a custom column in Power Query:

Date.AddYears([Date],1)

Eyelyn9_0-1646366279760.png

And then change its type to Date. Below is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VczBDYAwDATBXvxGOp+tJFBL5P7bIEiA4+c8ducUUyM66BLHKyo4Cp0fDSxyuKYaemJsl5URVxH/zp9nwtF2sKdOmETc", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.AddYears([Date],1)),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}})
in
    #"Changed Type1"

Eyelyn9_1-1646366469360.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-eqin-msft
Community Support
Community Support

Hi @Keiser ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it.

 

Best Regards,
Eyelyn Qin

v-eqin-msft
Community Support
Community Support

Hi  @Keiser ,

 

Agree with @edhans , please use EDATE() to add years.

Or you could use Date.AddYears() to a custom column in Power Query:

Date.AddYears([Date],1)

Eyelyn9_0-1646366279760.png

And then change its type to Date. Below is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VczBDYAwDATBXvxGOp+tJFBL5P7bIEiA4+c8ducUUyM66BLHKyo4Cp0fDSxyuKYaemJsl5URVxH/zp9nwtF2sKdOmETc", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.AddYears([Date],1)),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}})
in
    #"Changed Type1"

Eyelyn9_1-1646366469360.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

edhans
Super User
Super User

Don't use DATEADD to add dates. This is a time intelligence function that creates a table of dates. To add days, just use +1 for one day. To add years, use the EDATE function.

 

EDATE('Table'[Column1], 12)
 
That will add 12 months to all dates and compensate for leap year. 
edhans_0-1646156474910.png

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Keiser
Frequent Visitor

Thanks so much for that, what formula could I use to add 2 years or more?

Just use increments of 12, So 12, 24, 36 for 1, 2, 3 years.

 

EDATE('Table'[Column1], 36)

 

would add 3 years.

 

See this article, as well as a bit of info on EOMONTH. EDATE – DAX Guide

Both might be helpful for you here. 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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
Top Kudoed Authors