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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
unknown917
Helper III
Helper III

Sequential Order column based on multiple criteria

 

I am in need of creating a column "sequential order"  that will assign numerical order to each unique subset under the hub.  Here's the catch...the hub parent should always be first & not all hubs have subsets.  Each subset in the hub gets numbered sequentially.  Below is the desired result column "Seq Order".  Any help will be greatly appreciated.

 

HubHub NameSubset IDSubset NameSeq Order
1FW FW0
2INA702INA0
2INA624GUAVA1
3SB SB0
4LLLE700LLLE0
4LLLE203APPLE1
4LLLE521BANANA2
4LLLE700GRAPE3
4LLLE136ORANGE4
4LLLE953PEAR5
4LLLE630MANGO6
4LLLE631PINEAPPLE7
4LLLE632COCONUT8
5COL028COL0
6CIN609CIN0
7DTN DTN0
8MAR MAR0
9TWI TWI0
10MID MID0
11SP SP0
12PTB PTB0
13BEC BEC0
14STO STO0
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @unknown917 ,

 

Do a group by the hub then add a new column with the following code:

Table.AddIndexColumn ([HubRows], "Seq Order",0)

Now expand the columns you need to see.

 

Full code below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZHBDoMgEER/pfHcA2LVekRqDYkFotgejP//G93B5VDpZTO8YZcBtq0oi2vx/FC5HGK/boUkaayi2oqkf3kjb1THVb0Pp6LV0vMUEmDYMU3TEMeItDg5UqBVeZ9btUS2XlnFx2cDx1n5rK2sGqpuVnbMvK7GaX5Q89lpKgx8UZPLLeTwxg5/YzYVnkU77ewaolnH9URVyDtrcOTSxqJHdKzBW9KPYPn1oEDvMc/M9MWR0Rc+hikUaBnDm0faTCpiBF98+hZ/QMT1IX0WVMR4mX7QjKEixk2X4NIMUvv+BQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hub = _t, #"Hub Name" = _t, #"Subset ID" = _t, #"Subset Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hub", Int64.Type}, {"Hub Name", type text}, {"Subset ID", Int64.Type}, {"Subset Name", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Hub"}, {{"HubRows", each _, type table [Hub=nullable number, Hub Name=nullable text, Subset ID=nullable number, Subset Name=nullable text, Seq Order=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn ([HubRows], "Seq Order",0)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Hub Name", "Subset ID", "Subset Name", "Seq Order"}, {"Hub Name", "Subset ID", "Subset Name", "Seq Order"})
in
    #"Expanded Custom"

MFelix_0-1772457653208.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @unknown917 ,

 

Do a group by the hub then add a new column with the following code:

Table.AddIndexColumn ([HubRows], "Seq Order",0)

Now expand the columns you need to see.

 

Full code below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZHBDoMgEER/pfHcA2LVekRqDYkFotgejP//G93B5VDpZTO8YZcBtq0oi2vx/FC5HGK/boUkaayi2oqkf3kjb1THVb0Pp6LV0vMUEmDYMU3TEMeItDg5UqBVeZ9btUS2XlnFx2cDx1n5rK2sGqpuVnbMvK7GaX5Q89lpKgx8UZPLLeTwxg5/YzYVnkU77ewaolnH9URVyDtrcOTSxqJHdKzBW9KPYPn1oEDvMc/M9MWR0Rc+hikUaBnDm0faTCpiBF98+hZ/QMT1IX0WVMR4mX7QjKEixk2X4NIMUvv+BQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hub = _t, #"Hub Name" = _t, #"Subset ID" = _t, #"Subset Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hub", Int64.Type}, {"Hub Name", type text}, {"Subset ID", Int64.Type}, {"Subset Name", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Hub"}, {{"HubRows", each _, type table [Hub=nullable number, Hub Name=nullable text, Subset ID=nullable number, Subset Name=nullable text, Seq Order=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn ([HubRows], "Seq Order",0)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Hub Name", "Subset ID", "Subset Name", "Seq Order"}, {"Hub Name", "Subset ID", "Subset Name", "Seq Order"})
in
    #"Expanded Custom"

MFelix_0-1772457653208.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





So much to learn!  Thank you @MFelix 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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 Solution Authors