Forum Discussion

SJG's avatar
SJG
New Member
3 years ago
Solved

Combining Multiple Columns to One

Hello,   I have survey data that comes in a pretty poor format and need assistance reformatting. When a question is asked multiple times in the survey, each response is placed in a new column. An e...
  • sevenhills's avatar
    3 years ago

    Yes it is possible.

     

    Here is the M Query code

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYiMgNlaK1YlWcsIQcUYViQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, Position = _t, Position2 = _t, Position3 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Person", type text}, {"Position", Int64.Type}, {"Position2", Int64.Type}, {"Position3", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Person"}, "Attribute", "Value"),
        #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute", "Person"}),
        #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "Position"}})
    in
        #"Renamed Columns"

     

    Your source:

     

     

    Output: