Forum Discussion
unknown917
5 months agoHelper 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 al...
- 5 months ago
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
5 months agoSuper 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"
unknown917
5 months agoHelper IV
So much to learn! Thank you MFelix