Forum Discussion
Transform columns into rows
- 3 years ago
Hi Anonymous ,
How about this? Note, I could not name multiple columns with the same name though.
Before:
After:
The trick here was to use unpivot columns 🙂
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilTSUTI0ABJGIMLQEEQYK8XqRCuFA5kWIEFTMAHE5kqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FatherID = _t, A = _t, B = _t, A.1 = _t, B.1 = _t]), #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"FatherID", "A.1", "B.1"}, "Attribute", "Value1"), #"Unpivoted Columns1" = Table.UnpivotOtherColumns(Source, {"FatherID", "A", "B"}, "Attribute", "Value2"), #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns1", "Attribute", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Attribute", "Attribute.2"}), #"Merged Queries" = Table.NestedJoin(#"Unpivoted Columns", {"FatherID", "Attribute"}, #"Split Column by Delimiter", {"FatherID", "Attribute"}, "Split Column by Delimiter", JoinKind.LeftOuter), #"Expanded Split Column by Delimiter" = Table.ExpandTableColumn(#"Merged Queries", "Split Column by Delimiter", {"Value2"}, {"Value2"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded Split Column by Delimiter",{"A.1", "B.1"}) in #"Removed Columns"Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Hi Anonymous ,
How about this? Note, I could not name multiple columns with the same name though.
Before:
After:
The trick here was to use unpivot columns 🙂
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilTSUTI0ABJGIMLQEEQYK8XqRCuFA5kWIEFTMAHE5kqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FatherID = _t, A = _t, B = _t, A.1 = _t, B.1 = _t]),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"FatherID", "A.1", "B.1"}, "Attribute", "Value1"),
#"Unpivoted Columns1" = Table.UnpivotOtherColumns(Source, {"FatherID", "A", "B"}, "Attribute", "Value2"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns1", "Attribute", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Attribute", "Attribute.2"}),
#"Merged Queries" = Table.NestedJoin(#"Unpivoted Columns", {"FatherID", "Attribute"}, #"Split Column by Delimiter", {"FatherID", "Attribute"}, "Split Column by Delimiter", JoinKind.LeftOuter),
#"Expanded Split Column by Delimiter" = Table.ExpandTableColumn(#"Merged Queries", "Split Column by Delimiter", {"Value2"}, {"Value2"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Split Column by Delimiter",{"A.1", "B.1"})
in
#"Removed Columns"
Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Hey! I got it here, the trick I see was using unpivot columns separately, them merging both new columns, that was a very good trick hahaha!