Forum Discussion
Format date of column headers after pivoting
- 5 years ago
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