Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hola a todos,
Hace poco vi el post de ayer de Fernando Elecno ( Transformar Tabla Verticalmente ). Quería ver si lo siguiente era posible mediante un enfoque similar mediante la función unpivot o la característica PowerQuery. He tratado de manipularlo, sin embargo, me estoy tomente con problemas. Lógicamente, quiero hacer esto
Mi tabla actual:
PersonID | LampDemand | ChairDemand | TableDemand | LampEstimate | ChairEstimate | TableEstimate |
1000 | 24 | 12 | 6 | 12 | 6 | 3 |
1001 | 20 | 10 | 5 | 8 | 4 | 2 |
1002 | 16 | 8 | 4 | 4 | 2 | 1 |
Mi salida/requisito deseado:
Ejemplo:
PersonID | Artículo/Tipo | Demanda | Estimación |
1000 | Lámpara | 24 | 12 |
1000 | Silla | 12 | 6 |
1000 | Mesa | 6 | 3 |
1001 | Lámpara | 20 | 8 |
1001 | Silla | 10 | 4 |
1001 | Mesa | 5 | 2 |
1002 | Lámpara | 16 | 4 |
1002 | Silla | 8 | 2 |
1002 | Mesa | 4 | 1 |
Quiero no sólo transformar el vector de tabla verticalmente, sin embargo, también quiero manipular y anexar la estructura de la tabla. Relaciona los 3 elementos con las categorías respectivas. Por ejemplo, lista/grupo por Lámpara, Presidente y Tabla como identificadores para que pueda relacionarlos con sus valores "Demanda" y "Estimar". Me pregunto si PowerQuery es incluso el enfoque correcto o debería investigar para tratar de abordar esto con R/ Python.
Muchas gracias de antemano por cualquier nota, consejos y sugerencias.
Mejor
Aaron
Hola @asmith147
Sí, eso es cosa para Power Query.
Primero se despivotan los demás (que la primera columna).
A continuación, divida la columna Attribute para separar los tipos de elemento del tipo de valor, antes de
Devolver los tipos de valor.
Pegue el siguiente código en el editor avanzado y siga los pasos:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIyARKGRkDCDJlhrBSrA1ZjCFIDUmgIIkyB2AKIQZqMYEpAegzNkGQgskBBpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [PersonID = _t, LampDemand = _t, ChairDemand = _t, TableDemand = _t, LampEstimate = _t, ChairEstimate = _t, TableEstimate = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"PersonID", Int64.Type}, {"LampDemand", Int64.Type}, {"ChairDemand", Int64.Type}, {"TableDemand", Int64.Type}, {"LampEstimate", Int64.Type}, {"ChairEstimate", Int64.Type}, {"TableEstimate", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"PersonID"}, "Attribute", "Value"),
#"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}), {"Attribute.1", "Attribute.2"}),
#"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.2]), "Attribute.2", "Value")
in
#"Pivoted Column"
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
¡¡Muchas gracias!! Esto funcionó, eché un vistazo a los pasos, así como el código. Muy útil. ¡Seguiré afilando mi conocimiento del código M!
Todo lo mejor y gracias de nuevo!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |
User | Count |
---|---|
2 | |
2 | |
2 | |
2 | |
1 |