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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
vazmor
Helper II
Helper II

Pivot Column, Multiple Row to Column.

Hello.

Currently I have a table like the one in the image, which has many rows with the title next to the value, I need to pass it to a table like the one in the image faster, because the original file has many columns. I know it can be done with Pivot Column, but it takes longer. I hope your help. Thank you.

vazmor_0-1602014382829.png

 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @vazmor 

 

check out this solution. This code fetches the rawdata of every second column with offset 1 and uses every second column the first entry as column name.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYicgNgFiZyA2V4rVgcgYQWVMoTIWcBljqIwZVMZSKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}, {"Column3", type text}, {"Column4", Int64.Type}, {"Column5", type text}, {"Column6", Int64.Type}}),
    CreateData = List.Transform
    (
        List.Alternate(Table.ColumnNames(#"Changed Type"), 1,1),
        (columnname)=> Table.Column(#"Changed Type", columnname)
    ),
    CreateColumnnames = List.Transform
    (
        List.Alternate(Table.ColumnNames(#"Changed Type"), 1,1,1),
        (header)=> Table.Column(#"Changed Type", header){0}
    ),
    CreateFinalTable = Table.FromColumns
    (
        CreateData,
        CreateColumnnames
    )
in
    CreateFinalTable

 

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

View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hello @vazmor 

 

check out this solution. This code fetches the rawdata of every second column with offset 1 and uses every second column the first entry as column name.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYicgNgFiZyA2V4rVgcgYQWVMoTIWcBljqIwZVMZSKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}, {"Column3", type text}, {"Column4", Int64.Type}, {"Column5", type text}, {"Column6", Int64.Type}}),
    CreateData = List.Transform
    (
        List.Alternate(Table.ColumnNames(#"Changed Type"), 1,1),
        (columnname)=> Table.Column(#"Changed Type", columnname)
    ),
    CreateColumnnames = List.Transform
    (
        List.Alternate(Table.ColumnNames(#"Changed Type"), 1,1,1),
        (header)=> Table.Column(#"Changed Type", header){0}
    ),
    CreateFinalTable = Table.FromColumns
    (
        CreateData,
        CreateColumnnames
    )
in
    CreateFinalTable

 

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

Thanks, Excelent Solution

edhans
Super User
Super User

Can you please post some data @vazmor per links below - from that image it looks like all you've done is removed some columns, renamed Column4 to Fecha and change the date format to show the integer vs date.

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors