Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
freelensia
Advocate II
Advocate II

Format date of column headers after pivoting

I have a table with country, date, and a value column. I want to pivot the date column so that I can see the value progressing over each day (each row in the table is a Monday of the week).

freelensia_0-1604029450237.png

 

let
    Source = AdvWeeklyStats,
    DelCol = Table.RemoveColumns(Source,{"New infections", "New deaths", "Total deaths", "Day of Week"}),
    SortByDate = Table.Sort(DelCol,{{"Date", Order.Ascending}, {"Country", Order.Ascending}}),
    PivotCol = Table.Pivot(Table.TransformColumnTypes(SortByDate, {{"Date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(SortByDate, {{"Date", type text}}, "en-US")[Date]), "Date", "Total infections")
in
    PivotCol

 

 

However after pivoting my date column headers are displayed in m-d-yyyy format.

freelensia_1-1604029767537.png

How can I display them in yyyy/m format? Keeping in mind I do not want a monthly aggregate ! Each record must still pivot to its own column, and there should be 4 columns for each month like this:

 

2020/3 2020/3 2020/3 2020/3 2020/4 2020/4 2020/4 2020/4 2020/5 ...

 

 

If I change en-US to ja-JP then I get the dates formatted as yyyy/mm/dd which is a good start, but not what I need. I looked at this thread but the inner function was too complicated for me to replicate in my case.

 

Can anybody help me?
@Jimmy801 @Greg_Deckler @amitchandak @parry2k @Mariusz @ImkeF 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @freelensia 

 

column headers have to be unique. So why not using weeks instead of months? Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TczBDcAgDEPRXXxGyEkoPXeH3lD2XwNQq4Sb9WT9MfC8KKBWWlWuKfDyq/RQTVULtVRjaEvlKrRPr6NrW2VrP7qM7w33CQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, Date = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}, {"Date", type date}, {"Value", Int64.Type}}, "de-DE"),
    #"Calculated Week of Year" = Table.TransformColumns(#"Changed Type",{{"Date", each Text.From(Date.WeekOfYear(_))&"/"&Text.From(Date.Year(_)), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Calculated Week of Year", List.Distinct(#"Calculated Week of Year"[Date]), "Date", "Value", List.Sum)
in
    #"Pivoted Column"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

1 REPLY 1
Jimmy801
Community Champion
Community Champion

Hello @freelensia 

 

column headers have to be unique. So why not using weeks instead of months? Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TczBDcAgDEPRXXxGyEkoPXeH3lD2XwNQq4Sb9WT9MfC8KKBWWlWuKfDyq/RQTVULtVRjaEvlKrRPr6NrW2VrP7qM7w33CQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, Date = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}, {"Date", type date}, {"Value", Int64.Type}}, "de-DE"),
    #"Calculated Week of Year" = Table.TransformColumns(#"Changed Type",{{"Date", each Text.From(Date.WeekOfYear(_))&"/"&Text.From(Date.Year(_)), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Calculated Week of Year", List.Distinct(#"Calculated Week of Year"[Date]), "Date", "Value", List.Sum)
in
    #"Pivoted Column"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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