Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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).
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.
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
Solved! Go to Solution.
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
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
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
8 | |
6 | |
6 | |
6 |