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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Sorting by two things in table

Hi Team,

I have a table that looks like the below (example). I'd like to filter by Item and then cost. 

For example, i'd expect row 2 to be "A, TAS, 2, Three" and row 3 to be "A, QLD, 1, two" . 

I have tried to sort in query editor mode, but when back in my table visual, it does not sort poperly. Any help is much appreciated.

ItemstateCostSupplier
ANSW4one
AQLD1two
ATAS2three
BNSW3one
BVIC4two
CNSW5one
CQLD4two
CTAS6three
1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@Anonymous,

 

Table can be sorted by multiple columns, but I'm afraid this can only be achieved in power query. In power query, click advanced editor using M code like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUfILDgeSJkCcn5eqFKsDEQ30cQGShkBcUp4PFw1xDAaSRiDRjKJUiGonuBnGSGaARMM8naEmw8xwhqs1RVLrDLcPXS3EPjOEfbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Item = _t, state = _t, Cost = _t, Supplier = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"state", type text}, {"Cost", Int64.Type}, {"Supplier", type text}}),
    Result = Table.Sort(#"Changed Type",{{"Item", Order.Ascending}, {"Cost", Order.Descending}})
in
    Result

Capture.PNG 

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@Anonymous,

 

Table can be sorted by multiple columns, but I'm afraid this can only be achieved in power query. In power query, click advanced editor using M code like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUfILDgeSJkCcn5eqFKsDEQ30cQGShkBcUp4PFw1xDAaSRiDRjKJUiGonuBnGSGaARMM8naEmw8xwhqs1RVLrDLcPXS3EPjOEfbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Item = _t, state = _t, Cost = _t, Supplier = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"state", type text}, {"Cost", Int64.Type}, {"Supplier", type text}}),
    Result = Table.Sort(#"Changed Type",{{"Item", Order.Ascending}, {"Cost", Order.Descending}})
in
    Result

Capture.PNG 

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

May I clarify that when you say power query do you mean query editor within PowerBI? 

@Anonymous,

 

Yes, the code I've put is in query editor.

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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