Forum Discussion
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
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.
2. Right click on Table and choose new colum and apply the formula
Let me know if any help
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:
[dateFormatted] will now be of type date, formatted as: dd Mmm yyyy
16 Replies
- gpsuserAdvocate I
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:
[dateFormatted] will now be of type date, formatted as: dd Mmm yyyy
- AilleryOMemorable Member
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
- TheirenAdvocate I
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 Text2. 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.
- harshularoraNew Member
i have a similar issue and i keep getting an error, i tried almost everything still it shows error,
- brentlightseyAdvocate III
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])
- SQLMongerAdvocate II
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.
- BaskarResident Rockstar
Create new column using DAX
Create new calculated Column
- AnonymousNot 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.
- BaskarResident Rockstar
Do u want to change YYYYMMDD to date ? right.
my formula ii give u the date column as date, yyyy-mm-dd
- kalyanNew Member
New column with below formula worked for me
DateKey = FORMAT(Table1[DateColumn1].[Date],"YYYYMMDD")
- AnonymousNot applicable
Dear Baskar, I don't have modeling tab in my power bi.
I create a new column, see attached screenshot.
Which formula has I to insert there to convert from column Date:20220105 (YYYYmmDDto a valid date format?
Many thanks for your support