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
Anonymous
Not applicable

Transformar, manipular, anexar tabla verticalmente

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

2 REPLIES 2
ImkeF
Super User
Super User

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

Anonymous
Not applicable

@ImkeF

¡¡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!

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.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

Top Solution Authors