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
PolarBear
Helper I
Helper I

Búsqueda (en varias tablas) con condición If en la fecha

Necesito crear una tabla basada en los valores de otras tres tablas. Cada vez que se introduce una nueva fecha para un ID en cualquiera de las tres tablas, la nueva fecha debe agregarse a la nueva tabla junto con la entrada más reciente para el ID de las tres tablas.

IdFechaEstado
33211/10/20 8:34 AMRojo
34001/10/20 1:52 PMNull
34121/11/20 7:28 AMVerde
34821/12/20 2:24 PMAmarillo
35121/13/20 9:32 AMAmarillo
34001/13/20 11:22 AMAmarillo
IdFechaClientes afectados
33211/10/20 8:34 AMtodo
34001/10/20 1:52 PMNull
34121/11/20 7:28 AMNinguno
34821/12/20 2:24 PMNinguno
35121/13/20 9:32 AMtodo
34001/13/20 11:22 AMNinguno
33211/15/20 3:41 PMNinguno
IdFechaSeveridad
33211/10/20 8:34 AMAlto
34001/10/20 1:52 PMNull
34121/11/20 7:28 AMBajo
34821/12/20 2:24 PMBajo
35121/13/20 9:32 AMAlto
34001/13/20 11:22 AMBajo

Resultados esperados

IdFechaEstadoClientes afectadosSeveridad
33211/10/20 8:34 AMRojotodoAlto
34001/10/20 1:52 PMNullNullNull
34121/11/20 7:28 AMVerdeNingunoBajo
34821/12/20 2:24 PMAmarilloNingunoBajo
35121/13/20 9:32 AMAmarillotodoAlto
34001/13/20 11:22 AMAmarilloNingunoBajo
33211/15/20 3:41 PMRojoNingunoAlto
1 ACCEPTED SOLUTION

Hola @PolarBear ,

Puede manejarlo en Power Query Editor, pegue el siguiente código en Advance Editor y reemplace el nombre de la tabla por uno corregido:

let
    Source = Table.NestedJoin(t2, {"ID", "Date"}, t1, {"ID", "Date"}, "t1", JoinKind.LeftOuter),
    #"Expanded t1" = Table.ExpandTableColumn(Source, "t1", {"ID", "Date", "Status"}, {"t1.ID", "t1.Date", "t1.Status"}),
    #"Merged Queries" = Table.NestedJoin(#"Expanded t1", {"ID", "Date"}, t3, {"ID", "Date"}, "t3", JoinKind.LeftOuter),
    #"Expanded t3" = Table.ExpandTableColumn(#"Merged Queries", "t3", {"ID", "Date", "Severity"}, {"t3.ID", "t3.Date", "t3.Severity"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded t3",{"t1.ID", "t1.Date", "t3.ID", "t3.Date"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ID", "Date", "t1.Status", "Customers Affected", "t3.Severity"}),
    #"Sorted Rows1" = Table.Sort(#"Reordered Columns",{{"ID", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Sorted Rows" = Table.Sort(#"Sorted Rows1",{{"ID", Order.Ascending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"t1.Status", "t3.Severity"}),
    #"Renamed Columns" = Table.RenameColumns(#"Filled Down",{{"t1.Status", "Status"}, {"t3.Severity", "Severity"}})
in
    #"Renamed Columns"

merge.JPG

Puede encontrar mi archivo PBIX de ejemplo mediante este enlace.

Saludos

Rena

Community Support Team _ Rena
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

5 REPLIES 5
Greg_Deckler
Super User
Super User

No puedo conseguir que sus datos de muestra se muevan con los resultados esperados, específicamente para 3321, la segunda entrada.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler ,

Me disculpo, he pegado datos incorrectos... He actualizado mis resultados esperados.

Gracias

amitchandak
Super User
Super User

@PolarBear ,

Trate como

summarize(
New Table =
union(
selectcolumns(Table1,"ID",[ID],"Date",Table[Date],"Status",Table[Status],"Customers Affected","","Severity",""),

selectcolumns(Table2,"ID",[ID],"Date",Table[Date],"Status","","Customers Affected",Table[Customers Affected],"Severity",""),

selectcolumns(Table2,"ID",[ID],"Date",Table[Date],"Status","","Customers Affected","","Severity",Table[[Severity])

),
[ID],"Date",Max([Date]),"Status",max(Status)," Customers Affected",max([Customers Affected]),"Severity",max([Severity]))

@amitchandak , esto está cerca, pero necesito cada fecha que cualquiera de ellos cambió, con el nuevo valor y el valor más reciente de los que no cambiaron.

Hola @PolarBear ,

Puede manejarlo en Power Query Editor, pegue el siguiente código en Advance Editor y reemplace el nombre de la tabla por uno corregido:

let
    Source = Table.NestedJoin(t2, {"ID", "Date"}, t1, {"ID", "Date"}, "t1", JoinKind.LeftOuter),
    #"Expanded t1" = Table.ExpandTableColumn(Source, "t1", {"ID", "Date", "Status"}, {"t1.ID", "t1.Date", "t1.Status"}),
    #"Merged Queries" = Table.NestedJoin(#"Expanded t1", {"ID", "Date"}, t3, {"ID", "Date"}, "t3", JoinKind.LeftOuter),
    #"Expanded t3" = Table.ExpandTableColumn(#"Merged Queries", "t3", {"ID", "Date", "Severity"}, {"t3.ID", "t3.Date", "t3.Severity"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded t3",{"t1.ID", "t1.Date", "t3.ID", "t3.Date"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ID", "Date", "t1.Status", "Customers Affected", "t3.Severity"}),
    #"Sorted Rows1" = Table.Sort(#"Reordered Columns",{{"ID", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Sorted Rows" = Table.Sort(#"Sorted Rows1",{{"ID", Order.Ascending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"t1.Status", "t3.Severity"}),
    #"Renamed Columns" = Table.RenameColumns(#"Filled Down",{{"t1.Status", "Status"}, {"t3.Severity", "Severity"}})
in
    #"Renamed Columns"

merge.JPG

Puede encontrar mi archivo PBIX de ejemplo mediante este enlace.

Saludos

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.