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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Convert Rows to columns

Hi,

 

I have a csv file that look like this:

 

iditem_1value_1item_2value_2item_3value_3item_4value_4item_5value_5
1a1b2c3d4e5
2e3        
3c3        

 

 

And I want to look like this:

 

iditemvalue
1a1
1b2
1c3
1d4
1e5
2e3
3c3

 

With python or vba it will be easy, but I wan't to do it with power query. Is that posible?

 

Thank you,

 

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

This works with your sample data

Please see attached file's query editor for steps

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUoEYhCdBMRGQJwMxMZAnALEJkCcCsSmSrE60WDZVKisAl4MUm2MZBZ2FBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [id = _t, item_1 = _t, value_1 = _t, item_2 = _t, value_2 = _t, item_3 = _t, value_3 = _t, item_4 = _t, value_4 = _t, item_5 = _t, value_5 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"item_1", type text}, {"value_1", Int64.Type}, {"item_2", type text}, {"value_2", Int64.Type}, {"item_3", type text}, {"value_3", Int64.Type}, {"item_4", type text}, {"value_4", Int64.Type}, {"item_5", type text}, {"value_5", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"id"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute.1]), "Attribute.1", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Pivoted Column", each ([value] <> null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute.2"})
in
    #"Removed Columns"

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

This works with your sample data

Please see attached file's query editor for steps

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUoEYhCdBMRGQJwMxMZAnALEJkCcCsSmSrE60WDZVKisAl4MUm2MZBZ2FBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [id = _t, item_1 = _t, value_1 = _t, item_2 = _t, value_2 = _t, item_3 = _t, value_3 = _t, item_4 = _t, value_4 = _t, item_5 = _t, value_5 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"item_1", type text}, {"value_1", Int64.Type}, {"item_2", type text}, {"value_2", Int64.Type}, {"item_3", type text}, {"value_3", Int64.Type}, {"item_4", type text}, {"value_4", Int64.Type}, {"item_5", type text}, {"value_5", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"id"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute.1]), "Attribute.1", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Pivoted Column", each ([value] <> null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute.2"})
in
    #"Removed Columns"
Anonymous
Not applicable

Thank you!

Helpful resources

Announcements
Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.