cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to change YYYYMMDD into date format?

Hello guys,

 

How can i change the '20170104' from column IDT_DTM_ID into 04-01-2017?

 

Kind regards,

 

Rega

 

2017-01-05 17_13_40-Orakel_performance - Query Editor.png

2 ACCEPTED SOLUTIONS
Baskar
Resident Rockstar
Resident Rockstar

No No,

 

u r trying to create in power Query window. so only it throws error.

 

i was gave u DAX Query.

 

U have to create new column in Development environment .

 

1. Create via Modelling Tab.

1.JPG

 

 

 

2. Right click on Table and choose new colum and apply the formula

2.JPG

 

 

Let me know if any help

 

 

 

View solution in original post

gpsuser
Regular Visitor

assume:  [date] is in the following format:  yyyymmdd

 

create a new column named [dateFormatted] and apply the formula as follows:

  • dateFormatted = Date(Left([date],4),Right(left([date],6),2),right([date],2)

select the new column and change its type to date as follows:

Capture.PNG

 

[dateFormatted] will now be of type date,   formatted as:   dd Mmm yyyy

View solution in original post

14 REPLIES 14
kalyan
New Member

New column with below formula worked for me

DateKey = FORMAT(Table1[DateColumn1].[Date],"YYYYMMDD")

brentlightsey
Advocate I
Advocate I

I also found that this simple formula would convert your date from a YYYYMMDD string to a true date. Add as a new column:

 

DateFormatted = Date.From([IDT_DTM_ID])

If your date, is stored as an integer, (DateKey column), and not text, a slight tweak on @brentlightsey  answer will do the trick:

 

Date.FromText( Number.ToText( [IDT_DTM_ID]))

 

You can then tweak the code in the advanced editor to add a data type conversion from text to a date value:

 

Original line: 

#"Added Custom" = Table.AddColumn(MyDataSource, "DateFormatted", each Date.FromText( Number.ToText( [IDT_DTM_ID])))

 

Add type cast:

 

#"Added Custom" = Table.AddColumn(MyDataSource, "DateFormatted", each Date.FromText( Number.ToText( [IDT_DTM_ID])) type date)

 

You can do the type conversion in the Power Query Editor, but I like keeping the script as clean as possible and try to combine steps whenever possible.

 

 

gpsuser
Regular Visitor

assume:  [date] is in the following format:  yyyymmdd

 

create a new column named [dateFormatted] and apply the formula as follows:

  • dateFormatted = Date(Left([date],4),Right(left([date],6),2),right([date],2)

select the new column and change its type to date as follows:

Capture.PNG

 

[dateFormatted] will now be of type date,   formatted as:   dd Mmm yyyy

View solution in original post

AilleryO
Continued Contributor
Continued Contributor

Hi,

I'm little late but might help others...

The fastest and easiest solution is to use the the "Column from example" and your dates should be recognized after you type in a transformation of one of your date.

So the folowing formula will not be needed. In case you don't like code, it is the best way.

 

If you like to write your own code, there is a M function you can use in customn column:

Date.From(Text.From([#"DATE AUGMENT ATION"])) if you have a numeric column

or 

Date.From([#"DATE AUGMENT ATION"])

(you also have the Date.fromText function, check out differences if needed)

Wishing you good transformation

Theiren
Frequent Visitor

I have a very simple way to do this in Power Query Editor (late, but might help others as @AilleryO also stated in his reply).

 

Three steps:

1. Change the date column type to Text

2. In case you have zero-values in your data (00000000), replace the 00000000 values with blank values, i.e. leave empty (this can be done in Transform tab --> Replace Values)

3. Change the date column type to Date

 

Note: If you don't need to do number 2., make a new step instead of replacing the previous one, otherwise it will skip the Text conversion and you'll end up of getting an error.

Baskar
Resident Rockstar
Resident Rockstar

Create new column using DAX

 

Create new calculated Column 

1.JPG

 

 

 

 

Anonymous
Not applicable

Hello,

 

Thank you for your message. i have cretated a new column and a new measure but i get the following error. there's something with the syntax for 4.

 

2017-01-06 16_05_25-Orakel_performance - Power BI Desktop.png

Baskar
Resident Rockstar
Resident Rockstar

Create new column not measure.

Anonymous
Not applicable

OK, i created a custom column and these new column call DATUM.

 

Still i get a error of Expression.Error: The name 'DATUM' wasn't recognized...

 

2017-01-06 16_19_35-Orakel_performance - Query Editor.png

 

what did i wrong?

 

 

Baskar
Resident Rockstar
Resident Rockstar

No No,

 

u r trying to create in power Query window. so only it throws error.

 

i was gave u DAX Query.

 

U have to create new column in Development environment .

 

1. Create via Modelling Tab.

1.JPG

 

 

 

2. Right click on Table and choose new colum and apply the formula

2.JPG

 

 

Let me know if any help

 

 

 

View solution in original post

for using data model, you need to use following expression when you add custom column

 

=Date.FromText(
Text.Range([Input Date as Sting], 0,4) & "-"  &
Text.Range([Input Date as Sting], 4,2) & "-" &
Text.Range([Input Date as Sting], 6,2)
)

More information here:

 

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

 

 






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Baskar
Resident Rockstar
Resident Rockstar

Table5 is your table Name.

 

Column1 is your column name.

 

Baskar
Resident Rockstar
Resident Rockstar

Do u want to change YYYYMMDD to date ? right.

my formula ii give u the date column as date, yyyy-mm-dd

 

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.