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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
credencial
Frequent Visitor

Advanced Sort Table

Hi folks,

 

I need help.

 

I need to sort each dotted rectangle as ascending by the "DATA" column for the same value columns: "RAZÃO", "COD_FORNE", "REFER_PRODUTO" and add a new INDICE (INDEX) column like this:

 

credencial_0-1625848055980.png

 

Its possible in M (preferably) or DAX?

 

Thanks for any help.

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @credencial 

 

Create a blank query and open its Advanced Editor. Then paste below codes to replace all codes in Advanced editor to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjAwVtJRcgRiCzMQK9DQSClWByplglvKFL8uJ7iUpaUlQsoMt5Q5bimYXcZmpuh2WeCWssQtZYIpFQsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DATA = _t, CODE = _t, REFER = _t, NAME = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DATA", Int64.Type}, {"CODE", type text}, {"REFER", Int64.Type}, {"NAME", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"CODE", "REFER", "NAME"}, {{"All", each _, type table [DATA=nullable number, CODE=nullable text, REFER=nullable number, NAME=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([All], "Index", 0, 1, Int64.Type)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"DATA", "CODE", "REFER", "NAME", "Index"}, {"DATA", "CODE", "REFER", "NAME", "Index"})
in
    #"Expanded Custom"

vjingzhang_0-1626257290937.png

Attach pbix file for your reference.

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @credencial 

 

Create a blank query and open its Advanced Editor. Then paste below codes to replace all codes in Advanced editor to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjAwVtJRcgRiCzMQK9DQSClWByplglvKFL8uJ7iUpaUlQsoMt5Q5bimYXcZmpuh2WeCWssQtZYIpFQsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DATA = _t, CODE = _t, REFER = _t, NAME = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DATA", Int64.Type}, {"CODE", type text}, {"REFER", Int64.Type}, {"NAME", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"CODE", "REFER", "NAME"}, {{"All", each _, type table [DATA=nullable number, CODE=nullable text, REFER=nullable number, NAME=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([All], "Index", 0, 1, Int64.Type)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"DATA", "CODE", "REFER", "NAME", "Index"}, {"DATA", "CODE", "REFER", "NAME", "Index"})
in
    #"Expanded Custom"

vjingzhang_0-1626257290937.png

Attach pbix file for your reference.

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

CNENFRNL
Community Champion
Community Champion

Easy job with PQ. First, group the table by the 3 columns; then add index to each grouped table.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Tanks for your reply @CNENFRNL.

Sorry, I couldn't see your solution. Can be more specific?

The columns are already grouped, they should only be sorted by the "DATE" column, but in sections as shown in the dotted line.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors