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

Tabla sin pivotar con diferentes campos

Hola a todos

He buscado y leído algunos mensajes sobre tablas pivotantes y unpivot; sin embargo, mis datos son un poco differnet y muy feo, necesito un poco de ayuda en esto:

Tabla que tengo:

IdMesAñoEquipo/Puntuación/MinutosValor 1Valor 2Valor 3
a202002EquipoEquipo XEquipo Y
a202002Puntuación55.7
a202002Minutos6065
b202001EquipoEquipo Z1Equipo Z2Equipo Z3
b202001Puntuación866.2
b202001Minutos605560
b202001EquipoEquipo Z4Equipo Z5Equipo Z6
b202001Puntuación8.14.87
b202001Minutos557080

Me gustaría pasar de aquí:

IdMesAñoEquipoPuntuaciónMinutos
a202002Equipo X560
a202002Equipo Y5.765
b202001Equipo Z1860
b202001Equipo Z2655
b202001Equipo Z36.260
b202001Equipo Z48.155
b202001Equipo Z54.870
b202001Equipo Z6780

Intenté crear una nueva tabla en DAX con union, pero no tuve éxito (https://community.powerbi.com/t5/Desktop/unpivot-table-with-milestones/m-p/951385#M455873). Parece que mi caso es más dinámico (cuz Team/Score/Minutes) y no sé cómo resolverlo.

Cualquier consejo sería apreciado!

5 REPLIES 5
Greg_Deckler
Super User
Super User

Este es un trabajo para @ImkeF o @edhans o alguien de habilidad similar. Creo que implicará una columna de índice y una columna personalizada que utiliza como MOD 3 o algo así y luego se agrupa en ella. No estoy seguro, pero esos 2 serán capaces de ayudar.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hola @trevorhh9 ,

por favor pegue este código en el editor advaned de una nueva consulta:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIyMDIwMAIyQlITc6GUQgSMEQlkKMXqoCkNTs4vSgXSpiCsZ45VjW9mXmlJajGQZWYAIkxhqpJgqgzRLI0yhLOM4CxjTD0w2y1AxoKwnhGmIjTrTU0hLPwOMIGzTOEsMzwO0APxTPRADjHH5wSw7eYgd1gAnRALAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, MonthYear = _t, #"Team/Score/Minutes" = _t, #"Value 1 " = _t, #"Value 2" = _t, #"Value 3" = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, 3), Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Integer-Divided Column", {"ID", "MonthYear", "Index"}, {{"Partition", each Table.PromoteHeaders(Table.Transpose(Table.RemoveColumns(_, {"ID", "MonthYear", "Index"})))}}),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Index"}),
    #"Expanded Partition" = Table.ExpandTableColumn(#"Removed Columns", "Partition", {"Team", "Score", "Minutes"}, {"Team", "Score", "Minutes"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Partition", each ([Team] <> ""))
in
    #"Filtered Rows"

Se ajusta automáticamente a más columnas de valor.

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

Hola @ImkeF ,

Gracias por la respuesta.

Traté de usar la consulta que proporcionó en power bi con los datos reales. Cuando hice el último paso para "#Expanded Partición", dio el valor nulo para todas las filas. Parece que no usé la columna [Equipo/Puntuaciones/Munites] y tal vez PBI no sabía qué valor devolver.

¿O estoy haciendo algo mal?

Hola @trevorhh9

Sí, es posible que tenga que reemplazar los nombres de columna en el código.

También puede eliminar los últimos pasos y hacer la expansión manualmente para que pueda ver lo que realmente hay allí.

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

Hola @ImkeF ,

Encontré el problema de que la columna "Equipo/Puntuaciones/Munites" en mis datos leídos no está en la tercera columna, por lo que cuando expando la tabla, se mostró nula como el orden es incorrecto.

Gracias por la brillante respuesta!

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.