Reply
Highlighted
Member
Posts: 374
Registered: ‎07-22-2016
Accepted Solution

Create (Month,Year) from date column

In PowerQuery / Editor I am wanting to create a column with Month ancd Year from a date colum.

 

What is the best way to go about this...I couldnt see a way to format the date column into (Month,Year)

 

Thanks


Accepted Solutions
Super User
Posts: 10,536
Registered: ‎07-11-2015

Re: Create (Month,Year) from date column

When I did an "Add Column From Examples", I got:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDRXitUBcYxAHAswx0TfFMEx1TdDcKB6LCEcI31jAyQ5INcQyo0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Added Custom Column" = Table.AddColumn(#"Changed Type", "Custom", each Text.Combine({Date.ToText([Date], "MMMM"), ", ", Date.ToText([Date], "yyyy")}), type text)
in
    #"Added Custom Column"

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

Proud to be a Datanaut!


View solution in original post


All Replies
Super User
Posts: 10,536
Registered: ‎07-11-2015

Re: Create (Month,Year) from date column

When I did an "Add Column From Examples", I got:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDRXitUBcYxAHAswx0TfFMEx1TdDcKB6LCEcI31jAyQ5INcQyo0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Added Custom Column" = Table.AddColumn(#"Changed Type", "Custom", each Text.Combine({Date.ToText([Date], "MMMM"), ", ", Date.ToText([Date], "yyyy")}), type text)
in
    #"Added Custom Column"

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

Proud to be a Datanaut!