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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
DavidNunes7
Helper I
Helper I

How to add an integer like year to a date column in table via DAX

Hello everyone, I need help with Dax syntax and measurements.

I currently have a table with a date column and an integer column that represents year I need to know how do I create a calculated column by adding the date with the integer

Example:

DavidNunes7_1-1667672845361.png

 

Thanks 

 
1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @DavidNunes7 , 

 

you can use the below DAX statement to create a calculated column:

New Column = 
var __year = YEAR( 'Table'[Date] )
var __month = MONTH( 'Table'[Date] )
var __day = DAY( 'Table'[Date] )
return
DATE( __year + 'Table'[Year] , __month , __day )

The result:

image.png

As calculated columns do not benefit from all the compression power of the Tabular model as natural columns are doing, I recommend creating this column using Power Query. You can use the below formula to add a custom column to your table using Power Query:

#date( 
    Date.Year( [Date] ) + [Year]
    , Date.Month( [Date] )
    , Date.Day( [Date] )
)

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom

 






Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey @DavidNunes7 , 

 

you can use the below DAX statement to create a calculated column:

New Column = 
var __year = YEAR( 'Table'[Date] )
var __month = MONTH( 'Table'[Date] )
var __day = DAY( 'Table'[Date] )
return
DATE( __year + 'Table'[Year] , __month , __day )

The result:

image.png

As calculated columns do not benefit from all the compression power of the Tabular model as natural columns are doing, I recommend creating this column using Power Query. You can use the below formula to add a custom column to your table using Power Query:

#date( 
    Date.Year( [Date] ) + [Year]
    , Date.Month( [Date] )
    , Date.Day( [Date] )
)

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom

 






Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Great solution!!!!
Thank You 😁

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors