Forum Discussion
Transform raw data with messed up structure
- 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
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