Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ferris
New 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: 

IDNameA1B1C1A2B2C2
1XA1B1C1A2B2C2

 

I want the A1 en A2 in the same column on different rows using DAX. So I want it to look like this: 

 

IDNameABC
1XA1B1C1
1XA2B2C2

 

Is this possible? 

Thanks in advance.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super 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"

 

View solution in original post

1 REPLY 1
amitchandak
Super User
Super 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"

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.