Forum Discussion
Unpivot Multiple Columns with different formats
- 5 years ago
Hi,
v-xuding-msft CNENFRNL Jimmy801 AlB
Thanks a lot for your aissists,
I have solved the issue in my "artificial" way:
I have imported the same table four times and edited them according the need:
Fist table - I have left there the basic columns and then first columns for 1st question and 1st score.
then I have did the same with the second table leaving there basics and columns for 2nd questions ans scores and so on..
Then I have just UNION all four tables :)))))
That's all :))
Hello George1973
here another approach. But FYI... this kind of transformation is almost not possible to do with the GUI alone. So you have to dive into M-language. You can replace the first two steps with your data source
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddC9CoMwGIXhe8msab4vsZq5nToUpaOIg2QoVAP+3H9jLeXE4uTBN4SH1LUgU4hElKPv3DS1FLai9La8UrJh30OWJHNJ9lReU6XDv2px0/z0Q0tyPf7o/Oi+u/oVhsJR0VB0VAyUdbM9q/C5+L4f3BxsTbJ6LXj532sPvQxejrwMXo68DF6OvAzebXOhC/Dy5s3U7n1JoTdTh14N3m1DYkgcJw1pd6GB9CGbPP+S3TC3WjTNGw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Num = _t, Process = _t, Date = _t, Survey_Code = _t, Question_1 = _t, Score_1 = _t, Question_2 = _t, Score_2 = _t, Question_3 = _t, Score_3 = _t, კითხვა4 = _t, Question_4 = _t, Identificator = _t, Comment = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Num", Int64.Type}, {"Process", type text}, {"Date", type date}, {"Survey_Code", type text}, {"Question_1", type text}, {"Score_1", type text}, {"Question_2", type text}, {"Score_2", type text}, {"Question_3", type text}, {"Score_3", type text}, {"კითხვა4", type text}, {"Question_4", type text}, {"Identificator", Int64.Type}, {"Comment", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Question_4", "Score_4"}, {"კითხვა4", "Question_4"}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Num", "Process", "Date", "Survey_Code", "Identificator", "Comment"}, "Attribute", "Value"),
TransformAttribute = Table.TransformColumns
(
#"Unpivoted Other Columns",
{
{
"Attribute",
each if Text.StartsWith(_, "Score") then "Score" else "Question"
}
}
),
#"Pivoted Column" = Table.Pivot(TransformAttribute, List.Distinct(TransformAttribute[Attribute]), "Attribute", "Value", each _),
Add = Table.AddColumn
(
#"Pivoted Column",
"Table",
each Table.FromColumns({[Question], [Score]}, {"Question", "Score"})
),
#"Removed Columns" = Table.RemoveColumns(Add,{"Question", "Score"}),
#"Expanded Table" = Table.ExpandTableColumn(#"Removed Columns", "Table", {"Question", "Score"}, {"Question", "Score"})
in
#"Expanded Table"
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
WoW! Looks and sounds very promising 🙂
I will try and let you know later on