Forum Discussion
Format Date Column
Hello.
I have a dataflow in the power BI Service. There is a date column (Date) which needs to be as a text data type (dont ask why) and needs to be in a specific format.
Currently the date column is in the dd/mm/yyyy format.
I need to change this so its in the yyyy-MM-dd format , but as a string.
I have added the following code
Try this: Table.TransformColumns(Navigation, {{"YYYY-MM-DD", each Date.ToText(_, "yyyy-MM-dd"), type text}}) and see if this solves your problem
8 Replies
- _AAndradeResident Rockstar
Hi,
Try this code:Date.ToText([Date], "yyyy-MM-dd")- PPStarHelper V
Thanks. That worked.
Do you know how i can alter the existing M code - so we dont create a new column
At the moment i have this M code
#"Added custom" = Table.AddColumn(Navigation, "Custom", each Date.ToText([#"Date"], "yyyy-MM-dd")),#"Transform columns" = Table.TransformColumnTypes(#"Added custom", {{"Custom", type text}})This create a new column called Custom. Whilst this works. I want to acheive the same without creating a new columnCan we just modify the existing column to ensure its in yyyy-MM-dd format and as text?
- _AAndradeResident Rockstar
Yes it's possible. Please try this:
Table.TransformColumns(Navigation, {[#"Date"], each Date.ToText(_, "yyyy-MM-dd")})Instead of "Table.AddColumn(Navigation, "Custom", each Date.ToText([#"Date"], "yyyy-MM-dd"))"
- PPStarHelper V
Whilst visually, this looks correct, i just tried it and it gives me this error :
Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?
DetailsReason = Expression.ErrorAny ideas- _AAndradeResident Rockstar
I use tha name of my column Date where I want to transform.
Probably the error is on the [#"Date"]. Replace this column name for your column date name.