Luckywang
Hola, soy un nuevo usuario de Power BI y tengo una pregunta en este momento,
Hay cuatro factores en la tabla, ID, A, B y C. Quiero agrupar por ID en base al valor en A, B y C.
por ejemplo, para el ID # 1, hay un valor (mayor que 0) en el factor B, por lo que debe marcarse como grupo B.
Para el ID # 2, tiene valor en el factor A y B, por lo que debería tenerlo tanto en el Grupo A como en el Grupo B.
IDENTIFICACIÓN | A | B | C |
1 | 0 | 2 | 0 |
2 | 1 | 1 | 0 |
3 | 0 | 0 | 2 |
4 | 1 | 0 | 1 |
¿Alguien puede dar alguna idea de quién debería hacer esto?
Anónimo
En la consulta de energía, seleccione la columna ID y luego desvíe otras columnas.
Filtrar el valor en <> 0
o si buscas algo más parecido a esto:
Puedes usar este código:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nRR0lFyBGInIHZWitWJVjIEsgyA2AhMg0RALEMohogYQ9VA1IFETODyIDo2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"ID"}, "Attribute", "Value"), #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> 0)), #"Grouped Rows" = Table.Group(#"Filtered Rows", {"ID"}, {{"Count", each _, type table}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.SelectRows ( [Count], each [Value] >0 )), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Table.SelectColumns( [Custom], {"Attribute"} )), #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each Table.ToList( [Custom.1] )), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"Count", "Custom.2"}), #"Added Custom3" = Table.AddColumn(#"Removed Other Columns", "Factor ID", each List.Accumulate( [Custom.2], "", (state,current) => state & current), type text), #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Custom.2"}), #"Expanded Count" = Table.ExpandTableColumn(#"Removed Columns", "Count", {"ID", "Attribute", "Value"}, {"ID", "Attribute", "Value"}), #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Count",{{"ID", Int64.Type}, {"Attribute", type text}}) in #"Changed Type2"
Anónimo
En la consulta de energía, seleccione la columna ID y luego elimine las otras columnas.
Filtrar el valor en <> 0
o si buscas algo más parecido a esto:
Puedes usar este código:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nRR0lFyBGInIHZWitWJVjIEsgyA2AhMg0RALEMohogYQ9VA1IFETODyIDo2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"ID"}, "Attribute", "Value"), #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> 0)), #"Grouped Rows" = Table.Group(#"Filtered Rows", {"ID"}, {{"Count", each _, type table}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.SelectRows ( [Count], each [Value] >0 )), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Table.SelectColumns( [Custom], {"Attribute"} )), #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each Table.ToList( [Custom.1] )), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"Count", "Custom.2"}), #"Added Custom3" = Table.AddColumn(#"Removed Other Columns", "Factor ID", each List.Accumulate( [Custom.2], "", (state,current) => state & current), type text), #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Custom.2"}), #"Expanded Count" = Table.ExpandTableColumn(#"Removed Columns", "Count", {"ID", "Attribute", "Value"}, {"ID", "Attribute", "Value"}), #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Count",{{"ID", Int64.Type}, {"Attribute", type text}}) in #"Changed Type2"
Luckywang
En respuesta a Anónimo
Hola ~ gracias por tu respuesta, lo intentaré y creo que tu resultado me dijo que funcionará.
LivioLanzo
Hola @Luckywang
puede desvincular las columnas ‘A’, ‘B’ y ‘C’ y luego filtrar los ceros. Con Power Query esto debería ser bastante fácil
Luckywang
En respuesta a LivioLanzo
¡Hola, gracias por su respuesta! ¡voy a intentarlo!