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

How do I create a date field using a text field that has year and month only.

I have a text field that contains year and month only (ex '201801'). How do i create a date field using this text field.

 

Thanks!

Sallee

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Well, in DAX you could do this:

 

Column = DATE(INT(LEFT([Column1],4)),INT(RIGHT([Column1],2)),1)

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Well, in DAX you could do this:

 

Column = DATE(INT(LEFT([Column1],4)),INT(RIGHT([Column1],2)),1)

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
bogomda
Helper II
Helper II

Sallee,

 

create a new column in same table with following code where varible _Date  can be equal to other column in a table with dates.

 

3rd argument of the DATE function defines a day. In my case the result will be 1/1/2018

 

=
VAR _Date = "201801"
RETURN
DATE(left(_Date,4),MID(_Date,5,2),1)

 

Anonymous
Not applicable

Hi, I have this formula

Businessdate = DATE(LEFT([BUS_YEAR_MTH],4),MID([BUS_YEAR_MTH],5,2),1)

 

but it is giving me this error:

Expression.Error: The name 'DATE' wasn't recognized. Make sure it's spelled correctly.

 

Thanks for your help!

Sallee

Hi @Anonymous 

Open Power BI Desktop,click on "New column" from the home menu, "DATE" function should be possible.

Reference:

DAX: DATE

 

Best Regards

Maggie

works fine for me. try to use this sample as per link below.

 

https://1drv.ms/x/s!AhUWZ84uo7UAgmM8kvkwm1THdmsj

 

Alternative solution, Greg offered, should also work fine, use either one.

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.