Forum Discussion

michellerob2000's avatar
3 years ago

Transposing from columns to rows

I need to move the names (col B) to rows assigned to the app group name - I've tried unpivot - I cannot work out how to do it.

 

For example

WP2CCAC - Kasia Barnert and Shelley Attfield on one row

 

Really would appreciate any advice on how to fix this, thank you in advance.

 

Michelle.

7 Replies

  • Hi Michelle,

     

    Creating varying numbers of columns for each of your names would be a pain. If you just want to condense your table to one row per [App Group Name], but retain all the [Description] information, then I'd group the table on [App Group Name] and add a description aggregatd column using the SUM operator. This will give you an error initially, but will give you the code structure in the formula bar, where you can replace the SUM section with Text.Combine, something like this:

    // Change this:
    Table.Group(previousStepName, {"App Group Name"}, {{"Description", each List.Sum([Description]), type nullable text}})
    
    // to this:
    Table.Group(previousStepName, {"App Group Name"}, {{"Description", each Text.Combine([Description], ", ")}})

     

    Pete

      • michellerob2000's avatar
        michellerob2000
        Helper I

        I don't know what I have done, but done a fresh one and just cannot group it, I wont give me the 2nd column in the grouping

        Help! 

         

        Michelle.

         

  • AntrikshSharma's avatar
    AntrikshSharma
    Community Champion

    michellerob2000 Paste this code in the advanced editor:

    let
        Source = 
            Table.FromRows (
                Json.Document (
                    Binary.Decompress (
                        Binary.FromText (
                            "i45WCg8wcnZ2dFbSUfJOLM5MVHBKLMpLLSpRitVBlgvOSM3JSa1UcCwpSctMzUlBljYwBCoISC1JLVJwzkgsyE3Mw5B1L0pMTlVwApqhFBsLAA==",
                            BinaryEncoding.Base64
                        ),
                        Compression.Deflate
                    )
                ),
                let
                    _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
                in
                    type table [ #"App Group Name" = _t, Description = _t ]
            ),
        ChangedType = 
            Table.TransformColumnTypes (
                Source,
                { { "App Group Name", type text }, { "Description", type text } }
            ),
        GroupedRows = 
            Table.Group (
                ChangedType,
                { "App Group Name" },
                { { "Result", each Text.Combine ( _[Description], " and " ), type text } }
            )
    in
        GroupedRows