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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
unknown917
Helper IV
Helper IV

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.