Forum Discussion
Repeat sequence number in power query
Kindly suggest how to get the below repeated sequence in power query, kindly help.
| Type | Repeate Sequence |
| A | 1 |
| A | 2 |
| A | 3 |
| B | 1 |
| B | 2 |
| B | 3 |
| B | 4 |
| C | 1 |
| C | 2 |
| D | 1 |
Hi Anonymous ,
Here a solution:
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1UElnXCQzkiki1JsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Type"}, {{"Grouping", each _, type table [Type=nullable text]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn ( [Grouping], "Index", 1 )), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Type", "Index"}, {"Type", "Index"}) in #"Expanded Custom"I used the steps described in here:
https://www.tackytech.blog/how-to-swiftly-take-over-power-query/#3_Create_ranks_and_indexes
Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/Hi, Anonymous
let f = (ch, num) => let a = {{ch, num}} in (if num = 1 then a else a & @f(ch, num - 1)), out = Table.Sort( Table.FromRows( f("A", 3) & f("B", 4) & f("C", 2) & f("D", 1), {"Type", "Repeat Sequence"} ), {"Type", {"Repeat Sequence", Order.Ascending}} ) in out
3 Replies
- tackytechtomMost Valuable Professional
Hi Anonymous ,
Here a solution:
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1UElnXCQzkiki1JsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Type"}, {{"Grouping", each _, type table [Type=nullable text]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn ( [Grouping], "Index", 1 )), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Type", "Index"}, {"Type", "Index"}) in #"Expanded Custom"I used the steps described in here:
https://www.tackytech.blog/how-to-swiftly-take-over-power-query/#3_Create_ranks_and_indexes
Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/ - AlienSxSuper User
Hi, Anonymous
let f = (ch, num) => let a = {{ch, num}} in (if num = 1 then a else a & @f(ch, num - 1)), out = Table.Sort( Table.FromRows( f("A", 3) & f("B", 4) & f("C", 2) & f("D", 1), {"Type", "Repeat Sequence"} ), {"Type", {"Repeat Sequence", Order.Ascending}} ) in out - AnonymousNot applicable
If I do that I am getting repeated output but need below table where value should not be repeated.
Type Repeate Sequence Value A 1 10 A 2 20 A 3 30 B 1 5 B 2 2 B 3 10 B 4 20 C 1 10 C 2 20 D 1 30