Forum Discussion

Merleau's avatar
Merleau
Helper II
6 years ago
Solved

Pivoting a column and merging linked fields

Hello, I have a table with multiple columns (more than 30) in no particular order. I need to create multiple columns by pivoting one of these columns. And populate them with associated information c...
  • ImkeF's avatar
    6 years ago

    Hi Merleau ,

    you can pivot on the Type-column and use a Text.Combine-function as the aggregation function on the "Programs"-column.
    Create a new query and paste this code into the advanced editor:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nQxVNJRcvQFEq556TmZxRlgNlBYNy8xN1UpVgemJgAkHlyQmAdUE4BDDURvSWJOZmIeLnPA4m5FqXnJWK0ywqrECF0J2AXO+UWpiXkBOJRg8RSKGmOYMY5FiUmZyVBjjLEqgfoJmxqIn3QDckqLgSz3otTUbAQX4blYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Type = _t, Programs = _t, Name = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Type", type text}, {"Programs", type text}, {"Name", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Type]), "Type", "Programs", each Text.Combine(_, ", "))
    in
        #"Pivoted Column"

     

    Enclosing a file a well.

     

  • Anonymous's avatar
    Anonymous
    6 years ago

    I'm not sure I understand this request correctly.

    I guess this modification of this expression:

     

    Table.AddColumn(#"Grouped Rows", "Custom", each [Count][Programs])

     

    to

     

    Table.AddColumn(#"Grouped Rows", "Custom", each List.Sort([Count][Programs]))