Forum Discussion

ksab23's avatar
ksab23
Helper I
3 years ago
Solved

Transform raw data with messed up structure

hello all,  I presume there will be no solution for this but before I endeavor on a tedious manual task I have to ask. I have a survey dataset that is simply put terrible. Instead of having one su...
  • Peter_Beck's avatar
    3 years ago

    Hi -

     

    It looks like you start with this:

     

    ...and want to end up with this...

     

    ... is that the case?

     

    If so, you should be able to use "Table.Pivot" to do this, I have attached an example below:

     

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi1OLVIwVNJRCi4tKkutBDMDS1OLSzLz88Acx/Si1FSlWB0CSo2AHJfM4kRU1UZ4DPbTdySs0AjsApCRsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [UserID = _t, Survey = _t, QuestionText = _t, QuestionResponse = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"UserID", type text}, {"Survey", type text}, {"QuestionText", type text}, {"QuestionResponse", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[QuestionText]), "QuestionText", "QuestionResponse")
    in
    #"Pivoted Column"

     

    This is done by selecting the "QuestionText" column, selecting "Pivot Column" under "Transform", and selecting "QuestionResponse" as the "Values" column. Be sure to select "Don't Aggregate" under the "Advanced" option, because you are not aggregating numbers. "QuestionText" becomse columns, with the appropriate value from "QuestionResponse" in each column.

     

    Hope this helps!

     

    Peter