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

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.

Reply
Syndicate_Admin
Administrator
Administrator

Transformar datos: ¿Transponer, Pivotar, Unpivot u otra idea?

Hola a todos

Tengo los siguientes datos de SAP:

AndreasKvis_0-1631393820299.png

Como puede ver, las 4 filas de datos son muy similares, a excepción de la columna asociada. Por lo tanto, le gustaría transformar y agrupar los datos en una solución similar a la siguiente:

AndreasKvis_1-1631394101217.png

¿Saben si esto se puede lograr a través de Power Query?

Nota: Los datos son solo datos ficticios, y en el conjunto de datos real, tengo múltiples notifactions con diferentes números de socios (en el ejemplo anterior hay 4 socios, sin embargo, puede variar de 3 a 6 partes.

De antemano - gracias por su ayuda

/Anónimo

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Hola

Este código M funciona

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Notification", Int64.Type}, {"Typ", type text}, {"Create On", type date}, {"Material", type text}, {"Partner", type text}}),
    Partition = Table.Group(#"Changed Type", {"Notification"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Typ", "Create On", "Material", "Partner", "Index"}, {"Typ", "Create On", "Material", "Partner", "Index"}),
    #"Added Prefix" = Table.TransformColumns(#"Expanded Partition", {{"Index", each "Partner " & Text.From(_, "en-IN"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Partner")
in
    #"Pivoted Column"

Espero que esto ayude.

Untitled.png

View solution in original post

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Hola

Este código M funciona

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Notification", Int64.Type}, {"Typ", type text}, {"Create On", type date}, {"Material", type text}, {"Partner", type text}}),
    Partition = Table.Group(#"Changed Type", {"Notification"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Typ", "Create On", "Material", "Partner", "Index"}, {"Typ", "Create On", "Material", "Partner", "Index"}),
    #"Added Prefix" = Table.TransformColumns(#"Expanded Partition", {{"Index", each "Partner " & Text.From(_, "en-IN"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Partner")
in
    #"Pivoted Column"

Espero que esto ayude.

Untitled.png

Syndicate_Admin
Administrator
Administrator

Hola, para tu caso, ¿no sería mejor dividirlo en una tabla de hechos y dimensiones?
A continuación se muestra el trato que hice:

Basándome en los datos creé dos tablas

Part_1.png

Entonces creé la relación:

Part_2.png
Entiendo que de esta manera sus análisis serán mucho más fáciles.


Si desea descargar el archivo de ejemplo que creé, siga el enlace:
https://github.com/roolsant/SOSPowerBI/blob/main/Transform_Data.zip

Espero haberte ayudado.

Rodrigo Santos
https://www.linkedin.com/in/rodrigosanpbi/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors