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

Join 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.

Reply
toddwyx
New Member

how to sort on part of the headers

Hey guys, I would like to sort on part of my headers, I have sth like that:

primary event typesecondary eventtype2022-072022-062022-052022-042022-032022-022022-012021-12
eventevent583583583583583583583583
eventevent583583583583583583583583
eventevent7785583583583583583583583
eventevent583553458358358387864434583
eventevent58358344658843578583583583
eventevent583583583583583583583583

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

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

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".

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

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".

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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