I have a dataset which has many columns listing multiple years worth of values, example:
Country | 2020 Rank X | 2020 Rank Y | 2021 Rank X |
---|---|---|---|
EU | 1 | 2 | 3 |
USA | 2 | 3 | 4 |
Etc. Each year has about 6 values for each country and there is 4 years of data, approx 160 rows.
My problem is when attempting to display over time data, there is no functioning "year" column or any data Power BI recognises as a date. How do i convert from the year info in the column name to use-able/able to be filtered year information?
you should unpivot and pivot again on the Power Query side. then you can use DATE(<year>, <month>, <day>)
on the powerbi side...
try:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcg1VUNJRMgQRRiDCWClWJ1opNNgRIQIiTJRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, #"2020 Rank X" = _t, #"2020 Rank Y" = _t, #"2021 Rank X" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}, {"2020 Rank X", Int64.Type}, {"2020 Rank Y", Int64.Type}, {"2021 Rank X", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Country"}, "Attribute", "Value"),
#"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Year", each Text.Start([Attribute],4)),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Year", type date}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute]), "Attribute", "Value")
in
#"Pivoted Column"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.