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
Zyg_D
Continued Contributor
Continued Contributor

Agregación en un informe cuando los subvalores se convierten en nombres de columna

Estos son los datos:

data.JPG

En el informe quiero tener el siguiente tipo de agregación. ¿Cómo lograrlo?

result.JPG

1 ACCEPTED SOLUTION
Zyg_D
Continued Contributor
Continued Contributor

He votado respuestas útiles, pero ninguna de ellas ha respondido plenamente a la pregunta. Así que aquí voy a mostrar cómo hice lo que quería.

En primer lugar, Power Query:

let
    Source = Csv.Document(File.Contents("C:\Temp\PBI_example10.1.csv"),[Delimiter=",", Columns=3, Encoding=65001, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Name", type text}, {"Type", type text}, {"Categories", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Years", each Text.Split([Categories],",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Categories"}),
    #"Expanded Years" = Table.ExpandListColumn(#"Removed Columns", "Years"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Years",{{"Years", Int64.Type}})
in
    #"Changed Type1"

A continuación, visualización de matriz:

resultPBI.JPG

View solution in original post

7 REPLIES 7
Zyg_D
Continued Contributor
Continued Contributor

He votado respuestas útiles, pero ninguna de ellas ha respondido plenamente a la pregunta. Así que aquí voy a mostrar cómo hice lo que quería.

En primer lugar, Power Query:

let
    Source = Csv.Document(File.Contents("C:\Temp\PBI_example10.1.csv"),[Delimiter=",", Columns=3, Encoding=65001, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Name", type text}, {"Type", type text}, {"Categories", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Years", each Text.Split([Categories],",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Categories"}),
    #"Expanded Years" = Table.ExpandListColumn(#"Removed Columns", "Years"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Years",{{"Years", Int64.Type}})
in
    #"Changed Type1"

A continuación, visualización de matriz:

resultPBI.JPG

amitchandak
Super User
Super User

@Zyg_D , debe dividir el valor en filas en la consulta de energía. Consulte los pasos

https://www.tutorialgateway.org/how-to-split-columns-in-power-bi/

AllisonKennedy
Super User
Super User

Puede utilizar Columna dividida > Por delimitador.

Expanda Avanzadas y Dividir en ROWS.

Elija la columna como delimitador.

Todo esto hecho en Power Query Editor.

Una vez hecho esto, en la matriz de vista de informe o tabla dinámica coloque Categorías en columnas, Escriba filas y recuento de nombre en valores.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Zyg_D
Continued Contributor
Continued Contributor


@AllisonKennedy escribió:
Puede utilizar Columna dividida > Por delimitador.
Expanda Avanzadas y Dividir en ROWS.
Elija la columna como delimitador.
Todo esto hecho en Power Query Editor.
Una vez hecho esto, en la matriz de vista de informe o tabla dinámica coloque Categorías en columnas, Escriba filas y recuento de nombre en valores.

Gracias, Allison, por la sugerencia.

La cosa es que la columna "Categorías" se hace usando DAX. ¿Estoy pensando correctamente que ya no puedo aplicar Power Query en esta columna (ya que las manipulaciones de Power Query se realizan antes de jugar con DAX)?

@Zyg_D Sí, eso es correcto.

¿Cuál es el DAX para esta columna? Si se puede crear en DAX, normalmente puede volver a crearlo en Power Query. Proporcione la muestra más cruda de los datos y, a continuación, el resultado deseado.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Zyg_D
Continued Contributor
Continued Contributor


@AllisonKennedy escribió:

@Zyg_D Sí, eso es correcto.

¿Cuál es el DAX para esta columna? Si se puede crear en DAX, normalmente puede volver a crearlo en Power Query. Proporcione la muestra más cruda de los datos y, a continuación, el resultado deseado.


Gracias.

Voy a enlazar a otra pregunta con un ejemplo más crudo y el resultado deseado. No sé cómo mostrar rápidamente la fórmula DAX, ya que te di datos ficticios, así que para mí es un poco difícil recrear la fórmula que funcionaría en los valores que elegí en esta pregunta. Esperemos que pueda obtener la idea de los datos en la siguiente pregunta:
https://community.powerbi.com/t5/Desktop/Splitting-the-duration-into-column-names/m-p/1354837

He respondido a tu otra publicación también, pero como tus categorías son numéricas, puedes usar la función List.Numbers en M para que esto funcione:

Dejar
Source: Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYiMDQwswZWSgFKsTreSeLm5oCRYHqTeCCaCpN0JRb6EUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t á ((tipo de texto que acepta valores NULL) meta [Serialized.Text ? true]) en la tabla de tipos [Nombre , _t, Tipo , _t, Start_date , _t, End_date , _t]),
"Tipo de cambio" - Table.TransformColumnTypes(Source,"Name", type text,"Type", Int64.Type, "Start_date", Int64.Type,"End_date", Int64.Type),
"Añadido Personalizado" - Table.AddColumn(-"Changed Type", "Years", each List.Numbers([Start_date], [End_date]-[Start_date]+1,1)),
"Años ampliados" - Table.ExpandListColumn(-"Added Custom", "Years"),
"Changed Type1" á Table.TransformColumnTypes(''''''''''''Years'', Int64.Type')
En
"Tipo cambiado1"

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.