Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Power Query: combine dos tablas para obtener resultados precisos por fila.

Hola, Espero un poco de ayuda, por favor.

Tengo dos mesas

Una de ellas es para las visitas de auditoría de la tienda a continuación.

lennox25_0-1713278441505.png

La otra tabla es para una visita de cumplimiento a continuación. Será necesario separar esta tabla para que los consejos dados tengan su propia columna y todas las demás categorías se combinen en una columna.

lennox25_1-1713278510460.png

El resultado esperado es el siguiente. ¿Es esto posible?

lennox25_2-1713278615458.png

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Hola @lennox25,

Estoy usando algunos datos de su publicación inicial y aquí está mi solución:

1. Creé dos tablas como las tuyas: T_Stores y T_StoreDetail.
2. Realice las mismas transformaciones de datos en la tabla T_StoreDetail y el resultado final es este:

_AAndrade_0-1713280739314.png


El código M está aquí:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdKxCoMwEAbgV5HMQi5njDp2KoVuFjqIg9TYZkkhpj5/VaSVJKUZAx//f1yuaQhCXpGUHPpJ3WRyVJPU8xMFhYIiYEba9IOundFK35OztFaan8zJYpwCLohvSIhAYU6B75NCiGVOXRAxCuUeVSyACqcuhLCMQHMX5H+TeAwSESiDCDQLEB6qH09jk9p2wyD7RYmQcheFEQirCATu563oYjq13tRpHF9ym8pngal85J8nfFn7Bg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store No" = _t, Category = _t, #"Date Sold" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Store No", Int64.Type}, {"Category", type text}, {"Date Sold", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "OtherCat", each if [Category] <> "Advice Given" then "All other Categories" else [Category]),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Store No", "OtherCat"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[OtherCat]), "OtherCat", "Count")
in
    #"Pivoted Column"


3. Después de ir a T_Stores tabla y usar la opción de consulta merge, el resultado final es este:

_AAndrade_1-1713280831168.png



El código M está aquí:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtVTSUXLPz08BUkZm+gbm+kYGRsZKsTogSTMzoGhwYklmcVpickl+USVIkam+gQmKInOgqGduQVF+WWpual6JQl5qakoqyDxDA30DQ5BSE6hScwuEZYYW+kB5JHMsDTEtMzRHWBYLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store No" = _t, #"Audit Result" = _t, #"Audit Date" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Store No", Int64.Type}, {"Audit Result", type text}, {"Audit Date", type date}}),
    MergedQueries = Table.NestedJoin(ChangedType, {"Store No"}, T_StoreDetail, {"Store No"}, "T_StoreDetail", JoinKind.LeftOuter),
    ExpandedT_StoreDetail = Table.ExpandTableColumn(MergedQueries, "T_StoreDetail", {"Advice Given", "All other Categories"}, {"Advice Given", "All other Categories"})
in
    ExpandedT_StoreDetail



Excelente opción -¡Muchas gracias!

@lennox25 ¿Mi publicación resolvió su problema como @samratpbi ?
Si es así, por favor marque también mi publicación como una solución, me ayudará.
Gracias.

Syndicate_Admin
Administrator
Administrator

Hola
Creo que ni siquiera es necesario combinar tablas en Power Query. Lo que puedes hacer es unir las tablas usando la tienda No. y lleva todas las columnas de tu primera tabla a visual y crea 2 medidas como las siguientes:
Consejos dados =
CALCULAR (
COUNTROWS( T2),
T2. Categoría = "Consejos dados"
)
Otras categorías combinadas =
CALCULAR (
COUNTROWS( T2),
T2. Categoría <> "Asesoramiento dado"
)

Si esto resuelve su problema, márquelo como solución, ¡gracias!

Excelente -Gracias- esto ha resuelto fácilmente mi problema 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.