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
sdukes
Helper I
Helper I

Utilice Pivots para organizar correctamente mis datos

Hola a todos,

Me estoy perdiendo lo que espero que sea un simple paso aquí...

Tengo mis datos en este formato:

UbicaciónTipoEneroFebreroMarzo
A10.10.20.1
A20.20.10.1
A30.10.10.12
B10.10.120.2
B20.120.20.2
B30.20.050.1
C10.20.10.05
C20.10.050.1
C30.050.20.12

y no quiero llegar a este formato:

UbicaciónMesTipo 1Tipo 2Tipo 3
AEnero0.10.20.1
AFebrero0.20.10.1
AMarzo0.10.10.12
BEnero0.10.120.2
BFebrero0.120.20.05
BMarzo0.20.20.1
CEnero0.20.10.05
CFebrero0.10.050.2
CMarzo0.050.10.12

Cualquier consejo sería apreciado!

Gracias a todos,

Shmuel

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hola

Este código M funciona

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Type", Int64.Type}, {"Jan", type number}, {"Feb", type number}, {"Mar", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Location", "Type"}, "Attribute", "Value"),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN"), List.Distinct(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN")[Type]), "Type", "Value")
in
    #"Pivoted Column"

Espero que esto ayude.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hola

Este código M funciona

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Type", Int64.Type}, {"Jan", type number}, {"Feb", type number}, {"Mar", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Location", "Type"}, "Attribute", "Value"),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN"), List.Distinct(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN")[Type]), "Type", "Value")
in
    #"Pivoted Column"

Espero que esto ayude.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yiruan-msft
Community Support
Community Support

Hola @sdukes ,

Puede aplicar los pasos de unpivot y pivote en Power Query Editor para lograrlo, los códigos específicos como se indica a continuación:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYgM9CGkEZcfqQOSMUERR5YxRRMGkEVjSCc1QQ5gpMEkjVGFUSWMkUQNTJDud4cYiuweoBCaJJoyq0xhZGO6A2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, Type = _t, Jan = _t, Feb = _t, Mar = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Type", Int64.Type}, {"Jan", type number}, {"Feb", type number}, {"Mar", type number}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"Jan", "Feb", "Mar"}, "Attribute", "Value"),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Unpivoted Only Selected Columns", {"Location", "Attribute", "Value"}, "Attribute.1", "Value.1"),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Columns", {{"Value.1", type text}}, "zh-CN"),{"Attribute.1", "Value.1"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Reordered Columns" = Table.ReorderColumns(#"Merged Columns",{"Location", "Attribute", "Merged", "Value"}),
    #"Pivoted Column" = Table.Pivot(#"Reordered Columns", List.Distinct(#"Reordered Columns"[Merged]), "Merged", "Value")
in
    #"Pivoted Column"

unpivot and pivot.JPG Pasos aplicados en Power Query EditorBest Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
parry2k
Super User
Super User

@sdukes revisar mi entrada de blog aquí que más o menos hablar sobre el caso de uso similar

Me gustaría elogiossi mi solución ayudara.👉Si puedes pasar tiempo publicando la pregunta, también puedes hacer esfuerzos para dar a Kudos quien haya ayudado a resolver tu problema. ¡Es una muestra de agradecimiento!

Visítenos enhttps://perytus.com, su ventanilla única para proyectos/formación/consulta relacionados con Power BI.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.