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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Top Solution Authors