Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Change rows to colums

Hello everyone,

 

i have a table with 3 colums:

A   B   C

A - serial number
B - number 1 or 2
C - serial number

Well my task is:

A   B(1)  B(2)
     C       C

Thank you 


  • Jimmy801's avatar
    Jimmy801
    5 years ago

    Hello Anonymous 

     

    the Text.Combine has to be used as pivot-function of your third column. Here an example

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lFyAhHOhkqxOjABI5CAEUTACF2FEbKKWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
        #"Pivoted Column" = Table.Pivot(Source, List.Distinct(Source[B]), "B", "C", each Text.Combine(_,",")
    )
    in
        #"Pivoted Column"

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun und guten Rutsch 🙂

    Jimmy

4 Replies

  • Jimmy801's avatar
    Jimmy801
    Community Champion

    Hello Anonymous 

     

    your specification doesn't tell to much. However you can get the result by applying a pivoting-function on your 1or2 column using then SN1 as value column. But as I don't know to treat your value column, I simply applied a sum-function. This might not work in your scenario. Here the code

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJRMgTjWB0wxwiMY2MB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SN = _t, #"1or2" = _t, SN1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"SN", Int64.Type}, {"1or2", Int64.Type}, {"SN1", Int64.Type}}),
        #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"1or2", type text}}, "de-DE"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"1or2", type text}}, "de-DE")[#"1or2"]), "1or2", "SN1", List.Sum),
        #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"1", "1or2 - 1"}, {"2", "1or2 - 2"}})
    in
        #"Renamed Columns"

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works. 

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

  • Anonymous's avatar
    Anonymous
    Not applicable

     

    maybe this explains better 🙂

    • Jimmy801's avatar
      Jimmy801
      Community Champion

      Hello Anonymous 

       

      the Text.Combine has to be used as pivot-function of your third column. Here an example

      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lFyAhHOhkqxOjABI5CAEUTACF2FEbKKWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
          #"Pivoted Column" = Table.Pivot(Source, List.Distinct(Source[B]), "B", "C", each Text.Combine(_,",")
      )
      in
          #"Pivoted Column"

      Copy paste this code to the advanced editor in a new blank query to see how the solution works.

      If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
      Kudoes are nice too

      Have fun und guten Rutsch 🙂

      Jimmy

  • Anonymous's avatar
    Anonymous
    Not applicable

    TY!!! - Wünsche Dir auch