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.
Hola a todos,
Tengo un problema para generar la columna calculada "INDICE4" Quiero generar la "indece4" pero solo cambiar si la columna "índice" es distinta al valor anterior. Este es el ejemplo:
Los datos son:
Ciudad | Área | Organización | Artículo | De | Para | Operador | Índice | Índice | Indice2 |
N.Y. | NY_B2 | Company_T1 | Cantidad | 3 | 7 | Y | 10 | 1 | 1 |
N.Y. | NY_B2 | Company_T1 | Producto | PRD03 | PRD06 | O | 11 | 2 | 2 |
N.Y. | NY_B2 | Company_T1 | Producto | PRD08 | PRD013 | O | 12 | 2 | 3 |
N.Y. | NY_B2 | Company_T1 | Producto | PRD15 | PRD18 | O | 13 | 2 | 4 |
N.Y. | NY_B2 | Company_B5 | Cantidad | 1 | 3 | Y | 14 | 1 | 5 |
N.Y. | NY_B2 | Company_B5 | Producto | PRD04 | PRD06 | O | 15 | 2 | 6 |
N.Y. | NY_B2 | Company_B5 | Producto | PRD09 | PRD11 | O | 16 | 2 | 7 |
N.Y. | NY_D4 | Company_F5 | Cantidad | 2 | 4 | Y | 22 | 1 | 1 |
N.Y. | NY_D4 | Company_F5 | Producto | PRD02 | PRD05 | O | 23 | 2 | 2 |
N.Y. | NY_D4 | Company_F5 | Producto | PRD07 | PRD09 | O | 24 | 2 | 3 |
N.Y. | NY_D4 | Company_B2 | Cantidad | 1 | 3 | Y | 25 | 1 | 4 |
Muchas gracias por ayudarme, saludos...
Solved! Go to Solution.
En general, es más fácil crear columnas de índice en el editor de consultas en lugar de en DAX, por lo que estoy proporcionando una solución en M. Es posible en DAX, pero estoy pasando a escribir cosas de RANKX por el momento. Tal vez otro usuario salte.
Para obtener este índice, agruparía en las primeras cuatro columnas para establecer la granularidad del índice, luego agruparía en Ciudad y Área, generando un índice para cada una de estas, luego expandiría y fusionaría con la tabla original.
Aquí está la consulta M completa que puede pegar en su Editor avanzado para recorrer los pasos aplicados:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZFBD0NAEIX/i7OInd1Fj1XpUVvpRURE2otDaRoO/n1nGWIJ4jD71ka+zHsvSYzQii3DNMI48wH1Un2+edlmT4YfjyYv66Ju8cpxXJxzGODJbHV0k5rbjPuvejevWt2iwOakDuotUgD1D3RzjOSRMj6igFD8GIpJUm8kcSKJLZIv9YgYxUQRCXqSuwzdmFhEJGkb5yDpRL7YSHKI5M5IgZiQrjNffRCDL4CV6pcMfRsglcM2MKQ8r36P5E789SSx0rxG6uJa7QskPWHn6R8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [City = _t, Area = _t, Organization = _t, Item = _t, From = _t, To = _t, Operator = _t, Indice = _t, Index = _t, Indice2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"City", type text}, {"Area", type text}, {"Organization", type text}, {"Item", type text}, {"From", type text}, {"To", type text}, {"Operator", type text}, {"Indice", Int64.Type}, {"Index", Int64.Type}, {"Indice2", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"City", "Area", "Organization", "Item"},{}),
#"Grouped Rows1" = Table.Group(#"Grouped Rows", {"City", "Area"}, {{"AllRows", each Table.AddIndexColumn(_, "Index4", 1, 1, Int64.Type), type table [City=nullable text, Area=nullable text, Organization=nullable text, Item=nullable text, Index4=Int64.Type]}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows1", "AllRows", {"Organization", "Item", "Index4"}, {"Organization", "Item", "Index4"}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"City", "Area", "Organization", "Item"}, #"Expanded AllRows", {"City", "Area", "Organization", "Item"}, "Expanded AllRows", JoinKind.LeftOuter),
#"Expanded Expanded AllRows" = Table.ExpandTableColumn(#"Merged Queries", "Expanded AllRows", {"Index4"}, {"Index4"})
in
#"Expanded Expanded AllRows"
En general, es más fácil crear columnas de índice en el editor de consultas en lugar de en DAX, por lo que estoy proporcionando una solución en M. Es posible en DAX, pero estoy pasando a escribir cosas de RANKX por el momento. Tal vez otro usuario salte.
Para obtener este índice, agruparía en las primeras cuatro columnas para establecer la granularidad del índice, luego agruparía en Ciudad y Área, generando un índice para cada una de estas, luego expandiría y fusionaría con la tabla original.
Aquí está la consulta M completa que puede pegar en su Editor avanzado para recorrer los pasos aplicados:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZFBD0NAEIX/i7OInd1Fj1XpUVvpRURE2otDaRoO/n1nGWIJ4jD71ka+zHsvSYzQii3DNMI48wH1Un2+edlmT4YfjyYv66Ju8cpxXJxzGODJbHV0k5rbjPuvejevWt2iwOakDuotUgD1D3RzjOSRMj6igFD8GIpJUm8kcSKJLZIv9YgYxUQRCXqSuwzdmFhEJGkb5yDpRL7YSHKI5M5IgZiQrjNffRCDL4CV6pcMfRsglcM2MKQ8r36P5E789SSx0rxG6uJa7QskPWHn6R8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [City = _t, Area = _t, Organization = _t, Item = _t, From = _t, To = _t, Operator = _t, Indice = _t, Index = _t, Indice2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"City", type text}, {"Area", type text}, {"Organization", type text}, {"Item", type text}, {"From", type text}, {"To", type text}, {"Operator", type text}, {"Indice", Int64.Type}, {"Index", Int64.Type}, {"Indice2", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"City", "Area", "Organization", "Item"},{}),
#"Grouped Rows1" = Table.Group(#"Grouped Rows", {"City", "Area"}, {{"AllRows", each Table.AddIndexColumn(_, "Index4", 1, 1, Int64.Type), type table [City=nullable text, Area=nullable text, Organization=nullable text, Item=nullable text, Index4=Int64.Type]}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows1", "AllRows", {"Organization", "Item", "Index4"}, {"Organization", "Item", "Index4"}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"City", "Area", "Organization", "Item"}, #"Expanded AllRows", {"City", "Area", "Organization", "Item"}, "Expanded AllRows", JoinKind.LeftOuter),
#"Expanded Expanded AllRows" = Table.ExpandTableColumn(#"Merged Queries", "Expanded AllRows", {"Index4"}, {"Index4"})
in
#"Expanded Expanded AllRows"
@AlexisOlson Lo intento con su código M, y fue muy difícil porque soy nuevo en Power BI, DAX y M.
pero, su explicación fue muy útil.
Cambié su código M a este:
dejar
Origen = Excel.Workbook(File.Contents("C:\Users\danie\Desktop\Criterio Matriz.xlsx"), null, true),
Criteria_Table = Origen{[Item="Criteria",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"City", type text}, {"Area", type text}, {"Organization", type text}, {"Item", type text}, {"From", type text}, {"To", type text}, {"Operator", type text}}),
#"Filas agrupadas" = Table.Group(#"Changed Type", {"City", "Area", "Organization", "Item"},{}),
#"Grouped Rows1" = Table.Group(#"Grouped Rows", {"City", "Area"}, {{"AllRows", each Table.AddIndexColumn(_, "Index4", 1, 1, Int64.Type), escriba table [City=nullable text, Area=nullable text, Organization=nullable text, Item=nullable text, Index4=Int64.Type]}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows1", "AllRows", {"Organization", "Item", "Index4"}, {"Organization", "Item", "Index4"}),
#"Consultas combinadas" = Table.NestedJoin(#"Changed Type", {"City", "Area", "Organization", "Item"}, #"Expanded AllRows", {"City", "Area", "Organization", "Item"}, "Expanded AllRows", JoinKind.LeftOuter),
#"Expanded Expanded AllRows" = Table.ExpandTableColumn(#"Consultas combinadas", "Expanded AllRows", {"Index4"}, {"Index4"})
en
#"Expandido Expandido AllRows"
La 3ª línea (#"Changed Type" = ....) me da un error pero debo eliminar ese paso y funciona perfectamente.
Realmente aprecio su explicación, ejemplo, código, tiempo, ayuda, etc.
Saludos y gracias
Da un error ya que se refiere a un paso anterior "Fuente". Cuando eliminó ese paso, volvió a vincular automáticamente la referencia a #"Tipo cambiado" en el paso #"Fila agrupada" para hacer referencia a Critera_Table en su lugar, haciendo que todo funcione. 🙂
Observe cómo cada línea hace referencia a la anterior como el primer argumento en la función de tabla y tendrá una mejor comprensión de cómo corregir errores de referencia.
Gracias de nuevo por la explicación 👍🏼
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |