cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors