Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Repeat sequence number in power query

Kindly suggest how to get the below repeated sequence in power query, kindly help.

 

TypeRepeate Sequence
A1
A2
A3
B1
B2
B3
B4
C1
C2
D1
  • 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

  • tackytechtom's avatar
    tackytechtom
    Most 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/

  • 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
  • Anonymous's avatar
    Anonymous
    Not applicable

    If I do that I am getting repeated output but need below table where value should not be repeated.

     

    TypeRepeate SequenceValue
    A110
    A220
    A330
    B15
    B22
    B310
    B420
    C110
    C220
    D130