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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
JuanVR10
Frequent Visitor

Convertir columnas a filas en PowerQuery

Buenas tardes comunidad.

Espero me puedan ayudar con un problema en PowerQuery que no se si tiene solución.


Tengo una tabla con los registros Material - Clase de Movimiento y F.Contabilización

JuanVR10_0-1715287746549.png

Como el unico dato que se repite es Material, quiero ordenar mi tabla de la siguiente forma:

JuanVR10_1-1715287818092.png

de manera que en una fila quede el material y que se genere una nueva columna con las restantes 2 columnas.

Es decir, Clase de Mov, Fecha Contabilización, Clase de Mov2 y Fecha Contabilización.

 

He tratado de resolverlo con Pivot Columns y Unpivot Columns, pero no logro resolverlo.

Es posible realizar esto?

 

 

Gracias

Slds

Juan

 

1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Hi @JuanVR10 

 

Please try the following code:

let
    
    Source = Table.FromRecords({
        [Material = 40330098410, Clase de movimiento = 101, Fecha Contabilizacion = #date(2024, 9, 5)],
        [Material = 40330098410, Clase de movimiento = 601, Fecha Contabilizacion = #date(2024, 2, 1)]
    }),

    
    RemoveID = Table.RemoveColumns(Source, {"Material"}),

    
    #"Grouped Rows" = Table.Group(Source, "Material", {
        {"All Data", each Table.Pivot(
            Table.RemoveColumns(_, {"Material"}),
            List.Distinct(Table.TransformColumnTypes(_, {{"Fecha Contabilizacion", type text}}, "en-US")[Fecha Contabilizacion]),
            "Fecha Contabilizacion", "Clase de movimiento"
        )}
    }),

    #"Expanded Columns" = Table.ExpandTableColumn(#"Grouped Rows", "All Data", Table.ColumnNames(#"Grouped Rows"[All Data]{0}))
in
    #"Expanded Columns"

 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-jialongy-msft
Community Support
Community Support

Hi @JuanVR10 

 

Please try the following code:

let
    
    Source = Table.FromRecords({
        [Material = 40330098410, Clase de movimiento = 101, Fecha Contabilizacion = #date(2024, 9, 5)],
        [Material = 40330098410, Clase de movimiento = 601, Fecha Contabilizacion = #date(2024, 2, 1)]
    }),

    
    RemoveID = Table.RemoveColumns(Source, {"Material"}),

    
    #"Grouped Rows" = Table.Group(Source, "Material", {
        {"All Data", each Table.Pivot(
            Table.RemoveColumns(_, {"Material"}),
            List.Distinct(Table.TransformColumnTypes(_, {{"Fecha Contabilizacion", type text}}, "en-US")[Fecha Contabilizacion]),
            "Fecha Contabilizacion", "Clase de movimiento"
        )}
    }),

    #"Expanded Columns" = Table.ExpandTableColumn(#"Grouped Rows", "All Data", Table.ColumnNames(#"Grouped Rows"[All Data]{0}))
in
    #"Expanded Columns"

 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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