Forum Discussion
Index column based on other column
- 4 years ago
Group on Attribute column - Insert the required Index - Ungroup
See the working here for 2 columns table - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWBsIzgLGM4ywTMcgKyTOEsMzjLEM6C6HWG63CGy7rAZV3hJrvCZd0QrJg8KCcWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Attribute = _t, Answer = _t]), #"Grouped Rows" = Table.Group(Source, {"Attribute"}, {{"Temp", each _, type table [Attribute=nullable text, Answer=nullable text]}}), #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type), #"Expanded Temp" = Table.ExpandTableColumn(#"Added Index", "Temp", {"Answer"}, {"Answer"}) in #"Expanded Temp"
Group on Attribute column - Insert the required Index - Ungroup
See the working here for 2 columns table - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWBsIzgLGM4ywTMcgKyTOEsMzjLEM6C6HWG63CGy7rAZV3hJrvCZd0QrJg8KCcWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Attribute = _t, Answer = _t]),
#"Grouped Rows" = Table.Group(Source, {"Attribute"}, {{"Temp", each _, type table [Attribute=nullable text, Answer=nullable text]}}),
#"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
#"Expanded Temp" = Table.ExpandTableColumn(#"Added Index", "Temp", {"Answer"}, {"Answer"})
in
#"Expanded Temp"