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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Identificar registros con la fecha/hora más reciente

¿Alguna idea de por qué el siguiente lenguaje M no está produciendo los resultados deseados? Estoy tratando de agregar una nueva columna con un "1" para el registro 'wonum' con la marca de fecha y hora más reciente en el campo 'changedate' y un "0" para el no más reciente.

"Filtro de fecha añadido" ? Table.AddColumn("Eliminado otras columnas","Filtro de fecha", cada uno si [changedate] - List.Max(let currentwonum ? [wonum] en Table.SelectRows ("Eliminado otras columnas", cada [wonum] - currentwonum)[changedate]) entonces 1 más 0)

Mi solución fue modelada después de este post.

https://community.powerbi.com/t5/Desktop/Latest-Date-Filter/td-p/556579

Por @nwitstine y solución proporcionada por @v-jiascu-msft

Aquí están los datos de ejemplo y puede ver los resultados en la última columna. Debería haber algo de "1" ahí dentro.

wonumEstadochangedatechangebymemorándumsiteidFiltro de fecha
1001WAPPR9/21/2011 7:49SITTSJNullCg0
1001Aprox9/21/2011 7:57SITTSJNullCg0
1002WAPPR9/21/2011 7:59MERKELANullCg0
1002Aprox9/21/2011 8:12MERKELANullCg0
1005WAPPR9/21/2011 11:36MAXADMINNullCg0
1005Aprox9/21/2011 11:36MAXADMINNullCg0
1006WAPPR9/21/2011 11:41MAXADMINNullCg0
1006Aprox9/21/2011 11:41MAXADMINNullCg0
1007WAPPR9/21/2011 11:45MAXADMINNullCg0
1007Aprox9/21/2011 11:46MAXADMINNullCg0
1008WAPPR9/21/2011 11:47MAXADMINNullCg0
1008Aprox9/21/2011 11:47MAXADMINNullCg0
1009WAPPR9/21/2011 11:48MAXADMINNullCg0
1009Aprox9/21/2011 11:48MAXADMINNullCg0
1010WAPPR9/21/2011 11:48MAXADMINNullCg0
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Gracias @v-alq-msft .

Pude hacer ese trabajo, pero impactó gravemente en la peformancia de la consulta.

Terminé yendo con esta solución.

https://community.powerbi.com/t5/Desktop/Group-by-last-date/td-p/326382

View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hola, 4660042674

Según su descripción, creé datos para reproducir su escenario.

Puede agregar dos pasos como se indica a continuación.

= Table.AddColumn(#"Changed Type","Result", each let x=[wonum]in Table.Max(Table.SelectRows(#"Changed Type",each [wonum] = x),{"changedate"})[#"changedate"])

= Table.AddColumn(Custom1,"New",each if [changedate]=[Result] then 1 else 0)

Aquí están los códigos en el editor avanzado.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nc9NCoMwEIbhq5SsBfOlxvzsQivFthZRoYJ4A3Hn/Rs33TRjQ1YzDDy8zDQxcA6Wsbdr285PkwvkggMnZQvjD309DP3dL+u2LH5cbmzOviygpDpUgojJPdZU3aN6Osr9MG0hjpkM5gB7LnfoRndt6hclk2BJJQtEyCSoyKSMkEH470tNJlWETIKGTOoImQLBE5LzBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [wonum = _t, status = _t, changedate = _t, changeby = _t, memo = _t, siteid = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"wonum", Int64.Type}, {"status", type text}, {"changedate", type datetime}, {"changeby", type text}, {"memo", type text}, {"siteid", type text}}),
    Custom1 = Table.AddColumn(#"Changed Type","Result", each let x=[wonum]in Table.Max(Table.SelectRows(#"Changed Type",each [wonum] = x),{"changedate"})[#"changedate"]),
    Custom2 = Table.AddColumn(Custom1,"New",each if [changedate]=[Result] then 1 else 0)
in
    Custom2

Resultado:

e1.png

Saludos

Allan

Si este post ayuda,entonces por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Anonymous
Not applicable

Gracias @v-alq-msft .

Pude hacer ese trabajo, pero impactó gravemente en la peformancia de la consulta.

Terminé yendo con esta solución.

https://community.powerbi.com/t5/Desktop/Group-by-last-date/td-p/326382

Vvelarde
Community Champion
Community Champion

N.o 4660042674 Hola, tomo otra manera, pero el resultado es el deseado.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nc9NCoMwEIbhq5SsBfOlxvzsQivFthZRoYJ4A3Hn/Rs33TRjQ1YzDDy8zDQxcA6Wsbdr285PkwvkggMnZQvjD309DP3dL+u2LH5cbmzOviygpDpUgojJPdZU3aN6Osr9MG0hjpkM5gB7LnfoRndt6hclk2BJJQtEyCSoyKSMkEH470tNJlWETIKGTOoImQLBE5LzBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [wonum = _t, status = _t, changedate = _t, changeby = _t, memo = _t, siteid = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"changedate", type datetime}}, "en-US"),
    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Latest", each Table.SelectRows(#"Changed Type with Locale", let latest = List.Max(#"Changed Type with Locale"[changedate]) in each [changedate] = latest)),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each Table.Distinct(  Table.SelectColumns([Latest],"changedate"))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Latest"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"changedate"}, {"Custom.changedate"}),
    #"Added Custom2" = Table.AddColumn(#"Expanded Custom", "Custom", each if [changedate] = [Custom.changedate] then 1 else 0),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom2",{"Custom.changedate"})
in
    #"Removed Columns1"

img.png

saludos




Lima - Peru
Anonymous
Not applicable

Gracias @Vvelarde ,

Desafortunadamente, esa no es la solución a la que estoy apuntando. La solución identifica la marca de tiempo más reciente de todo el conjunto de datos. Estoy buscando identificar la marca de tiempo más reciente para cada wonum. Las dos primeras filas de la captura de pantalla son un ejemplo. Si hacemos que esto funcione, la primera fila será "0" y la segunda fila será "1".

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.