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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
arifulice09
Helper I
Helper I

Power Query row transformation into column

I have data in rows I need to convert into column (please find the attached), I have triyed several times but not getting the expected result.PQ Problem.PNG

 

2 ACCEPTED SOLUTIONS
AntrikshSharma
Super User
Super User

@arifulice09 Use this:

let
    Source = 
        Table.FromRows (
            Json.Document (
                Binary.Decompress (
                    Binary.FromText (
                        "i45W8g8NCfZ0cVUI8XBVCA7xD3JV0lFy8/EPr3HUdQty9HVVcDRUitUhRp0RkeqMweqc3UL8gVIgyhBdwAhdAKIl3D/Ix0XBOTQAKGpoYKgQnl+Uk6LgXFqARdYIr6wxmqyrY4hCuKuPD1ASxlQwMjDCI2eMR85EKTYWAA==",
                        BinaryEncoding.Base64
                    ),
                    Compression.Deflate
                )
            ),
            let
                _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
            in
                type table [ Heading = _t, Description = _t ]
        ),
    GroupedRows = 
        Table.Group (
            Source,
            { "Heading" },
            { { "Rows", each _, type table [ Heading = nullable text, Description = nullable text ] } }
        ),
    AddedIndex = Table.AddIndexColumn ( GroupedRows, "Index", 1, 1, Int64.Type ),
    AddedCustom = 
        Table.AddColumn (
            AddedIndex,
            "Custom",
            each
                let
                    Index = [Index],
                    ColumnNames = 
                        List.Transform (
                            Table.ColumnNames ( [Rows] ),
                            each _ & " " & Text.From ( Index )
                        ),
                    Data = 
                        {
                            { [Rows][Heading]{0} }
                                & List.Repeat ( { null }, List.Count ( [Rows][Description] ) - 1 ),
                            [Rows][Description]
                        },
                    Result = 
                        Table.ToColumns (
                            Table.FromRows ( { ColumnNames } ) 
                                & Table.FromColumns ( Data )
                        )
                in
                    Result
        ),
    CombineListsIntoTable = 
        Table.PromoteHeaders (
            Table.FromColumns ( List.Combine ( AddedCustom[Custom] ) )
        )
in
    CombineListsIntoTable

View solution in original post

arifulice09
Helper I
Helper I

@AntrikshSharma   wow what a solution is it ! Thanks a lot .

View solution in original post

2 REPLIES 2
arifulice09
Helper I
Helper I

@AntrikshSharma   wow what a solution is it ! Thanks a lot .

AntrikshSharma
Super User
Super User

@arifulice09 Use this:

let
    Source = 
        Table.FromRows (
            Json.Document (
                Binary.Decompress (
                    Binary.FromText (
                        "i45W8g8NCfZ0cVUI8XBVCA7xD3JV0lFy8/EPr3HUdQty9HVVcDRUitUhRp0RkeqMweqc3UL8gVIgyhBdwAhdAKIl3D/Ix0XBOTQAKGpoYKgQnl+Uk6LgXFqARdYIr6wxmqyrY4hCuKuPD1ASxlQwMjDCI2eMR85EKTYWAA==",
                        BinaryEncoding.Base64
                    ),
                    Compression.Deflate
                )
            ),
            let
                _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
            in
                type table [ Heading = _t, Description = _t ]
        ),
    GroupedRows = 
        Table.Group (
            Source,
            { "Heading" },
            { { "Rows", each _, type table [ Heading = nullable text, Description = nullable text ] } }
        ),
    AddedIndex = Table.AddIndexColumn ( GroupedRows, "Index", 1, 1, Int64.Type ),
    AddedCustom = 
        Table.AddColumn (
            AddedIndex,
            "Custom",
            each
                let
                    Index = [Index],
                    ColumnNames = 
                        List.Transform (
                            Table.ColumnNames ( [Rows] ),
                            each _ & " " & Text.From ( Index )
                        ),
                    Data = 
                        {
                            { [Rows][Heading]{0} }
                                & List.Repeat ( { null }, List.Count ( [Rows][Description] ) - 1 ),
                            [Rows][Description]
                        },
                    Result = 
                        Table.ToColumns (
                            Table.FromRows ( { ColumnNames } ) 
                                & Table.FromColumns ( Data )
                        )
                in
                    Result
        ),
    CombineListsIntoTable = 
        Table.PromoteHeaders (
            Table.FromColumns ( List.Combine ( AddedCustom[Custom] ) )
        )
in
    CombineListsIntoTable

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors