Forum Discussion
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
Como el unico dato que se repite es Material, quiero ordenar mi tabla de la siguiente forma:
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
- Anonymous2 years ago
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.
1 Reply
- AnonymousNot applicable
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.