Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hey guys, I would like to sort on part of my headers, I have sth like that:
primary event type | secondary eventtype | 2022-07 | 2022-06 | 2022-05 | 2022-04 | 2022-03 | 2022-02 | 2022-01 | 2021-12 |
event | event | 583 | 583 | 583 | 583 | 583 | 583 | 583 | 583 |
event | event | 583 | 583 | 583 | 583 | 583 | 583 | 583 | 583 |
event | event | 7785 | 583 | 583 | 583 | 583 | 583 | 583 | 583 |
event | event | 583 | 5534 | 583 | 583 | 583 | 8786 | 4434 | 583 |
event | event | 583 | 583 | 4465 | 884 | 3578 | 583 | 583 | 583 |
event | event | 583 | 583 | 583 | 583 | 583 | 583 | 583 | 583 |
I'm new to power BI, I have created a slicer on my primary and secondary event types, and I would like to sort my data based on the rest of the headers. However, I'm having trouble doing so. It would be helpful if someone can give some hints
Solved! Go to Solution.
The very first thing you want to do is bring the data into a usable format. You do that by unpivoting it.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSi1LzStR0oHTphbGJJCxOrQwwdzcwpQ6jjA1NsGqzcLcwgxImZjA5Qn5xMTEDOQmCwuQBmNTcwvahEYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"primary event type" = _t, #"secondary eventtype" = _t, #"2022-07" = _t, #"2022-06" = _t, #"2022-05" = _t, #"2022-04" = _t, #"2022-03" = _t, #"2022-02" = _t, #"2022-01" = _t, #"2021-12" = _t]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"primary event type", "secondary eventtype"}, "Attribute", "Value"),
#"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", Int64.Type}})
in
#"Changed Type"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
The very first thing you want to do is bring the data into a usable format. You do that by unpivoting it.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSi1LzStR0oHTphbGJJCxOrQwwdzcwpQ6jjA1NsGqzcLcwgxImZjA5Qn5xMTEDOQmCwuQBmNTcwvahEYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"primary event type" = _t, #"secondary eventtype" = _t, #"2022-07" = _t, #"2022-06" = _t, #"2022-05" = _t, #"2022-04" = _t, #"2022-03" = _t, #"2022-02" = _t, #"2022-01" = _t, #"2021-12" = _t]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"primary event type", "secondary eventtype"}, "Attribute", "Value"),
#"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", Int64.Type}})
in
#"Changed Type"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
58 | |
56 | |
56 | |
38 | |
29 |
User | Count |
---|---|
75 | |
62 | |
45 | |
40 | |
39 |