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

Datos dinámicos

Hola a todos

Tengo un problema en el que estoy tratando de pivotar los datos en una tabla para obtener un resultado en particular, pero estoy luchando por encontrar una solución.

Por ejemplo, tengo una tabla de datos similar a la siguiente donde cada ubicación en una fecha en particular tiene un valor alto y bajo.

davesab_0-1653332969637.png

Me gustaría de alguna manera pivotar o transformar los datos para que solo tenga una fila para cada fecha con los valores altos y bajos de ubicación que se muestran como columnas separadas.

davesab_1-1653333454115.png

Cualquier consejo o guía sobre cómo se puede lograr esto sería muy apreciado.

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

@davesab

Espero que esto sea lo que buscas.

Fowmy_0-1653334738917.png


Cree una consulta en blanco, vaya al Editor avanzado, borre el código existente y pegue los códigos que se indican a continuación y siga los pasos.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTXdSwo0jUyUtJRCsnPrswH0sYGZsZGYNrI0NBUKVYHVZlPfl5Kfh5Y3sTcFEwbG2Aq80stV4jML8oGK7AwhppnDlVogc1aA0NDIG1kYWFqgqkMbq2RpZGJMUSdIYYqFFuNTExMwQotjUD2xgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Location = _t, #"1.2 High" = _t, #"1.2 Low" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"1.2 High", Int64.Type}, {"1.2 Low", Int64.Type}, {"Date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date", "Location"}, "Attribute", "Value"),
    #"Added Custom Column" = Table.AddColumn(#"Unpivoted Other Columns", "Locations", each Text.Combine({Text.Start([Attribute], 4), [Location], Text.Middle([Attribute], 3)}), type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom Column",{"Location", "Attribute"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Locations]), "Locations", "Value", List.Sum)
in
    #"Pivoted Column"

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

@davesab ,

¿Qué tal esto?

tomfox_0-1653336106128.png

Aquí la Power Query en M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc0xDsIwDIXhq6DMles8OyS9A2LqgqpuMFWqJRbE7YlcQKJk8hs++Z+mEHPP2oOB0IXRlqfVK3wUgg9EiinM3U6ebL3a6kIzJR/C1JDn2+NwsfvipMjnaX7T0sxzrdaBUhJpQ37zGKAkG43/7idepSanA7w/vwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Location = _t, High = _t, Low = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Location", type text}, {"High", type number}, {"Low", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Location Low", each [Location] & " Low"),
    #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Location]), "Location", "High", List.Sum),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Tokyo", "Tokyo High"}, {"London", "London High"}, {"New York", "New York High"}}),
    #"Pivoted Column1" = Table.Pivot(#"Renamed Columns", List.Distinct(#"Renamed Columns"[#"Location Low"]), "Location Low", "Low", List.Sum),
    #"Grouped Rows" = Table.Group(#"Pivoted Column1", {"Date"}, {{"Tokyo High", each List.Max([Tokyo High]), type nullable number}, {"London High", each List.Max([London High]), type nullable number}, {"New York High", each List.Max([New York High]), type nullable number}, {"Tokyo Low", each List.Max([Tokyo Low]), type nullable number}, {"London Low", each List.Max([London Low]), type nullable number}, {"New York Low", each List.Max([New York Low]), type nullable number}})
in
    #"Grouped Rows"

Espero que esto ayude 🙂

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

Syndicate_Admin
Administrator
Administrator

@davesab

Espero que esto sea lo que buscas.

Fowmy_0-1653334738917.png


Cree una consulta en blanco, vaya al Editor avanzado, borre el código existente y pegue los códigos que se indican a continuación y siga los pasos.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTXdSwo0jUyUtJRCsnPrswH0sYGZsZGYNrI0NBUKVYHVZlPfl5Kfh5Y3sTcFEwbG2Aq80stV4jML8oGK7AwhppnDlVogc1aA0NDIG1kYWFqgqkMbq2RpZGJMUSdIYYqFFuNTExMwQotjUD2xgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Location = _t, #"1.2 High" = _t, #"1.2 Low" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"1.2 High", Int64.Type}, {"1.2 Low", Int64.Type}, {"Date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date", "Location"}, "Attribute", "Value"),
    #"Added Custom Column" = Table.AddColumn(#"Unpivoted Other Columns", "Locations", each Text.Combine({Text.Start([Attribute], 4), [Location], Text.Middle([Attribute], 3)}), type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom Column",{"Location", "Attribute"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Locations]), "Locations", "Value", List.Sum)
in
    #"Pivoted Column"

¡Eso es exactamente lo que estaba buscando! Gracias. 🙂

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.