Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

PIVOT/UNPIVOT

Good day,    I have problem to create nice columns of data I need. Due to complicated excel format of source files, I have following sample file structure:      What I'm looking for is the...
  • Jimmy801's avatar
    Jimmy801
    5 years ago

    Hello Anonymous 

     

    check out this code. Uses Table.Group to group data by question number. The function applied combines text from column2 and column1

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrdQ0lEKLE0tLsnMz1OK1YlWKkmtKFFIBIqCeSEgXhIKLxnGM7dE0qsA5MGVOKJowMaLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
        #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Column1", "Column2"}),
        GroupNumbers = Table.Group
        (
            #"Replaced Value",
            {"Column1"},
            {
                {
                    "AllRows",
                    each Text.Combine(_[Column2], " ") & " - " & Text.Combine(List.Skip(_[Column1],1)," ")
                }
            },
            GroupKind.Local,
            (group,current)=> try if Value.Is(Number.From(current[Column1]),type number) then 1 else 0 otherwise 0
        )
    in
        GroupNumbers

     

    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