cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

Cree una nueva columna a partir de otros valores de campo de tabla

Hola a todos,

Tengo una pregunta para crear una nueva tabla como se muestra a continuación.

Captured 2020-09-16_002.jpg

Ya tengo 'Tabla A' en mi Power BI y quiero obtener esas columnas booleanas como valor en Tipo booleano en la nueva tabla y obtener otra columna para contar el número de valores verdaderos.

¿Puede alguien ayudarme qué DAX necesito usar para obtener esta nueva tabla en Power BI?

1 ACCEPTED SOLUTION
Community Support
Community Support

Hola @wonygkim ,

La lógica de cálculo que @amitchandak da es correcta. Pero algunos detalles de las fórmulas deben corregirse. Por favor, intente esto:

Dax:

new table = 
UNION(
SUMMARIZE('Table', "Boolean Type" , "Boolean A","No of report", COUNTX(FILTER('Table', 'Table'[Boolean A] = "TRUE"), 'Table'[Boolean A])),
SUMMARIZE('Table', "Boolean Type" , "Boolean B","No of report", COUNTX(FILTER('Table', 'Table'[Boolean B] = "TRUE"),'Table'[Boolean B])),
SUMMARIZE('Table', "Boolean Type" , "Boolean C","No of report", COUNTX(FILTER('Table', 'Table'[Boolean C] = "TRUE"), 'Table'[Boolean C])),
SUMMARIZE('Table', "Boolean Type" , "Boolean D","No of report", COUNTX(FILTER('Table', 'Table'[Boolean D] = "TRUE"), 'Table'[Boolean D]))) 

M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilDSUQoJCnXFTsXqRCtFAjlujj7BrjhpkKoohE50RRCTYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Report = _t, #"Boolean A" = _t, #"Boolean B" = _t, #"Boolean C" = _t, #"Boolean D" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Report", type text}, {"Boolean A", type logical}, {"Boolean B", type logical}, {"Boolean C", type logical}, {"Boolean D", type logical}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Report"}, "Attribute", "Value"),
    #"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Attribute", "Value"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Value] = true)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"})
in
    #"Removed Columns"

2.gif

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Community Support
Community Support

Hola @wonygkim ,

La lógica de cálculo que @amitchandak da es correcta. Pero algunos detalles de las fórmulas deben corregirse. Por favor, intente esto:

Dax:

new table = 
UNION(
SUMMARIZE('Table', "Boolean Type" , "Boolean A","No of report", COUNTX(FILTER('Table', 'Table'[Boolean A] = "TRUE"), 'Table'[Boolean A])),
SUMMARIZE('Table', "Boolean Type" , "Boolean B","No of report", COUNTX(FILTER('Table', 'Table'[Boolean B] = "TRUE"),'Table'[Boolean B])),
SUMMARIZE('Table', "Boolean Type" , "Boolean C","No of report", COUNTX(FILTER('Table', 'Table'[Boolean C] = "TRUE"), 'Table'[Boolean C])),
SUMMARIZE('Table', "Boolean Type" , "Boolean D","No of report", COUNTX(FILTER('Table', 'Table'[Boolean D] = "TRUE"), 'Table'[Boolean D]))) 

M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilDSUQoJCnXFTsXqRCtFAjlujj7BrjhpkKoohE50RRCTYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Report = _t, #"Boolean A" = _t, #"Boolean B" = _t, #"Boolean C" = _t, #"Boolean D" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Report", type text}, {"Boolean A", type logical}, {"Boolean B", type logical}, {"Boolean C", type logical}, {"Boolean D", type logical}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Report"}, "Attribute", "Value"),
    #"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Attribute", "Value"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Value] = true)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"})
in
    #"Removed Columns"

2.gif

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

¡Muchas gracias! esto me ayuda a entender mucho mejor!

Super User IV
Super User IV

@wonygkim , Mejor despivot en Power Query y, a continuación, agregar allí.

https://radacad.com/pivot-and-unpivot-with-power-bi
Transponer : https://yodalearning.com/tutorials/power-query-helps-transposing-data/

https://radacad.com/power-bi-aggregation-step-1-create-the-aggregated-table

En dax resumiría y uniría

nueva tabla de la unión(
summarize(Table, "Boolean Type" , "No of report", countx(filter(Table, Table[Boolean A] á "True") Table[Boolean A])),
summarize(Table, "Boolean Type" , "No of report", countx(filter(Table, Table[Boolean b] á "True") Table[Boolean B])),
resume(Table, "Boolean Type" , "No of report", countx(filter(Table, Table[Boolean C] ? "True") Table[Boolean C])),
resume(Table, "Boolean Type" , "No of report", countx(filter(Table, Table[Boolean D] á "True") Table[Boolean D])))

Cambiar según la necesidad



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors