Forum Discussion

Incamus's avatar
Incamus
Regular Visitor
3 years ago
Solved

Index with repeated values

Dear all, good afternoon.

Can you help me with this problem?

 

Table with the code used:

 

 

let
Fonte = BD_Geral,
#"Outras Colunas Removidas" = Table.SelectColumns(Fonte,{"Nº CTe", "Nome"}),
#"Linhas Classificadas" = Table.Sort(#"Outras Colunas Removidas",{{"Nº CTe", Order.Ascending}}),
#"Linhas Agrupadas" = Table.Group(#"Linhas Classificadas", {"Nº CTe"}, {{"Tranportadoras", each _, type table [Nº CTe=nullable number, Nome=nullable text]}}),
#"Tranportadoras Agregado" = Table.AggregateTableColumn(#"Linhas Agrupadas", "Tranportadoras", {{"Nome", List.Distinct, "Contagem de Tranportadoras.Nome"}}),
#"Contagem de Tranportadoras.Nome Expandido" = Table.ExpandListColumn(#"Tranportadoras Agregado", "Contagem de Tranportadoras.Nome")
in
#"Contagem de Tranportadoras.Nome Expandido"

 

Desired result:

 

As an example of 52, it started with 0 and then went to 1. If there was a third repeated number, it would go to 2, and so on.

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Incamus ,

    Please refer the steps below.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpMVIrViVYyQjCNEUwTIDMpCc5MTgYzTYHMlBQw0wzITE2FM9PS4MyMDKXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Nº Cte" = _t, #"Contagem de Tranportadoras.Nome" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Nº Cte", Int64.Type}, {"Contagem de Tranportadoras.Nome", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Nº Cte"}, {{"Data", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type)}}),
        #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Contagem de Tranportadoras.Nome", "Index"}, {"Contagem de Tranportadoras.Nome", "Index"})
    in
        #"Expanded Data"

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Incamus ,

    Please refer the steps below.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpMVIrViVYyQjCNEUwTIDMpCc5MTgYzTYHMlBQw0wzITE2FM9PS4MyMDKXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Nº Cte" = _t, #"Contagem de Tranportadoras.Nome" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Nº Cte", Int64.Type}, {"Contagem de Tranportadoras.Nome", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Nº Cte"}, {{"Data", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type)}}),
        #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Contagem de Tranportadoras.Nome", "Index"}, {"Contagem de Tranportadoras.Nome", "Index"})
    in
        #"Expanded Data"

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

    • Incamus's avatar
      Incamus
      Regular Visitor

      The solution worked, thanks Anonymous