Forum Discussion
Ferris
3 years agoNew Member
Convert data in columns to rows
Hello,
I am fairly new to Power BI and this forum has helped me many times already. However I can't find the answer for the following problem.
I have data from a database that looks like this:
| ID | Name | A1 | B1 | C1 | A2 | B2 | C2 |
| 1 | X | A1 | B1 | C1 | A2 | B2 | C2 |
I want the A1 en A2 in the same column on different rows using DAX. So I want it to look like this:
| ID | Name | A | B | C |
| 1 | X | A1 | B1 | C1 |
| 1 | X | A2 | B2 | C2 |
Is this possible?
Thanks in advance.
Ferris , Try this in power query.
Paste the code in a blank query in power query
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYoAYkcQwwlEOIMIRyMQF0Q4GynFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t, A1 = _t, B1 = _t, C1 = _t, A2 = _t, B2 = _t, C2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name", type text}, {"A1", type text}, {"B1", type text}, {"C1", type text}, {"A2", type text}, {"B2", type text}, {"C2", type text}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Name", "ID"}, "Attribute", "Value"), #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}), #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value") in #"Pivoted Column"
1 Reply
- amitchandakSuper User
Ferris , Try this in power query.
Paste the code in a blank query in power query
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYoAYkcQwwlEOIMIRyMQF0Q4GynFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t, A1 = _t, B1 = _t, C1 = _t, A2 = _t, B2 = _t, C2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name", type text}, {"A1", type text}, {"B1", type text}, {"C1", type text}, {"A2", type text}, {"B2", type text}, {"C2", type text}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Name", "ID"}, "Attribute", "Value"), #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}), #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value") in #"Pivoted Column"