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
Anonymous
Not applicable

Date formatting

Hi,

I have a table (data) like this:

anbananand_0-1634645222502.png

I want to use first row as headers. But before that I want to change the date formats in that row as text as it looks (yyyy-mm-dd).

 

It there an easy way to do that?

 

Thanks in advance.

 

BR,

anbananand

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Anonymous 

 

In the Power Query Editor, convert this as data column and split the columns to month, date and Year and rearrange as Year,month and date.

Then select these 3 columns and right click -> select merge option. 

Promote the first row to header, the format will be retained.

rajendran_0-1634648986299.png

Thanks

Raj

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

HI @Anonymous 

 

In the Power Query Editor, convert this as data column and split the columns to month, date and Year and rearrange as Year,month and date.

Then select these 3 columns and right click -> select merge option. 

Promote the first row to header, the format will be retained.

rajendran_0-1634648986299.png

Thanks

Raj

mahoneypat
Microsoft Employee
Microsoft Employee

Just convert those columns to text before you promote headers (remove any existing Changed Type steps that convert them to Date type).  This assumes your original data is in the desired format.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat  thanks for your reply, the the format is automatically changed as below (MM/DD/YYYY):

anbananand_0-1634646849716.png

i still nead YYYY-MM-DD

Here is one way to do it after it is already promoted to headers in MM/DD/YYYY format.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.  You will want to use the Renamed Columns step in your query.

 

Note - you probably want to unpivot these columns anyway (which would simplify things).

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkhMzk5MT1XSUTLUN9I3MjAyBDLN9A3NIOxYnWglR5AkEBspxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",List.Zip({Table.ColumnNames(#"Promoted Headers"), List.Transform(Table.ColumnNames(#"Promoted Headers"), each if Text.Contains(_, "/") then Date.ToText(Date.FromText(_), "yyyy-MM-dd") else _)}))
in
    #"Renamed Columns"

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.