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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ss89
Helper II
Helper II

SORT BY MULTIPLE CONDITIONS

Hello Community,

 

I need to calculate SORT BY Column grouped by each LOT_NUMBER Column and sorted in an ascending STAGE SEQUENCE Column.

 

SORT BY Column should be like this:

LOT_NUMBERSTAGE SEQUENCESORT BY
001961
001972
001943
001924
001955
001936
001917
002051
002062
002033
002024
002045
002016

 

Thanks in advance for your support.

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @ss89 ,

 

Here I suggest you to add an index column grouped by LOT_NUMBER column in Power Query Editor.

Copy the code as below and paste it into Advanced Editor in Power Query Editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcyxCQAgDADBXVJbxKgRZwnZfw1FRL48eD5CVOuSIi5ZPibRCSMG0Yj6YIrswolGGNGJc8sN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [LOT_NUMBER = _t, #"STAGE SEQUENCE" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"LOT_NUMBER", Int64.Type}, {"STAGE SEQUENCE", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"LOT_NUMBER"}, {{"Count", each _, type table [LOT_NUMBER=nullable number, STAGE SEQUENCE=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"STAGE SEQUENCE", "Index"}, {"Custom.STAGE SEQUENCE", "Custom.Index"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Count"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.STAGE SEQUENCE", "STAGE SEQUENCE"}, {"Custom.Index", "Index"}})
in
    #"Renamed Columns"

New Table:

vrzhoumsft_0-1681715178689.png

For reference:Create Row Number for Each Group in Power BI using Power Query

 

Best Regards,
Rico Zhou

 

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

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @ss89 ,

 

Here I suggest you to add an index column grouped by LOT_NUMBER column in Power Query Editor.

Copy the code as below and paste it into Advanced Editor in Power Query Editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcyxCQAgDADBXVJbxKgRZwnZfw1FRL48eD5CVOuSIi5ZPibRCSMG0Yj6YIrswolGGNGJc8sN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [LOT_NUMBER = _t, #"STAGE SEQUENCE" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"LOT_NUMBER", Int64.Type}, {"STAGE SEQUENCE", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"LOT_NUMBER"}, {{"Count", each _, type table [LOT_NUMBER=nullable number, STAGE SEQUENCE=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"STAGE SEQUENCE", "Index"}, {"Custom.STAGE SEQUENCE", "Custom.Index"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Count"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.STAGE SEQUENCE", "STAGE SEQUENCE"}, {"Custom.Index", "Index"}})
in
    #"Renamed Columns"

New Table:

vrzhoumsft_0-1681715178689.png

For reference:Create Row Number for Each Group in Power BI using Power Query

 

Best Regards,
Rico Zhou

 

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

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.