Reply
Syndicate_Admin
Administrator
Administrator
Syndicated - Inbound

Devolver datos históricos mediante la consulta PowerBi

Source Community: Power BI | Source Author Name: jmupton

Hola, estoy tratando de mostrar datos históricos basados en varios filtros y luchando por obtener una consulta de búsqueda que funcione.

Por ejemplo, tengo una tabla con;

WORKNOUBICACIÓNPLAN DE TRABAJOESTADOFECHAFECHA DE CIERRE ANTERIOR
1234AB-12E1001ABRIR01/02/22??
4321AB-12E2001CERRADO01/01/22
5678AB-12E1001CERRADO01/11/21
8765AB-12E2001 CERRADO 01/01/21

Para WORKNO 1234 quiero buscar los WORKNO completados anteriormente y devolver la FECHA en que se cerró el PLAN DE TRABAJO E1001 más reciente, para la tabla anterior esto debería devolver 01/11/21. He probado varias funciones relacionadas con las últimas fechas completadas y los valores máximos, pero como el E1001 más reciente no se ajusta a ninguna de esas consultas, estoy luchando para devolver el valor correcto.

¡Cualquier ayuda sería apreciada!

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Source Community: Power BI | Source Author Name: JW_van_Holst
Syndicated - Inbound

Su conjunto de prueba es algo limitado, pero esto debería hacer el truco.

Picture1.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcxJCoAwEETRq0ivlaTaTFuH7MQILkPufw0bZ8TVh+JRORO4NVRT1zdgaYTWkKYlzhINpVkxU6kzmZbxpnzQYUprHE+MC1vnw8/vG0Mwdhy8s9/n6tbV8y1rKRs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [WORKNO = _t, LOCATION = _t, #"JOB PLAN" = _t, STATUS = _t, DATE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DATE", type date}}),
    Base = Table.Buffer(Table.Sort(#"Changed Type",{{"DATE", Order.Descending}})),
    #"Grouped Rows" = Table.Group(Base, {"JOB PLAN"}, {{"Data", each _, type table [WORKNO=nullable text, LOCATION=nullable text, JOB PLAN=nullable text, STATUS=nullable text, DATE=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Data], "Index", 0, 1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    IndexTable = Table.Buffer(Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"WORKNO", "LOCATION", "JOB PLAN", "STATUS", "DATE", "Index"}, {"WORKNO", "LOCATION", "JOB PLAN", "STATUS", "DATE", "Index"})),
    #"Added Custom1" = Table.AddColumn(IndexTable, "Custom", (outer)=> Table.SelectRows(IndexTable, each ([JOB PLAN]= outer[JOB PLAN]) and ([Index] = outer[Index]+1))[DATE]{0}),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom1", {{"Custom", null}})
in
    #"Replaced Errors"

Source Community: Power BI | Source Author Name: jmupton
Syndicated - Inbound

Gracias por la respuesta JW, parece que esto funcionará, ¡aprecie que el conjunto de datos de prueba se simplificó ya que no se pudo publicar el conjunto real como más de 14mil filas!

He seguido los pasos anteriores con mi conjunto de datos, cuando llego al siguiente paso;

 #"Added Custom1" = Table.AddColumn(IndexTable, "Custom", (outer)=> Table.SelectRows(IndexTable, each ([JOB PLAN]= outer[JOB PLAN]) and ([Index] = outer[Index]+1))[DATE]{0}),

No obtengo valores de error o fecha como ejemplo, la columna 'Personalizado' solo muestra 'Tabla' en cada celda, sin valores reales.

El enfoque final es ejecutar esto para múltiples ubicaciones con el mismo PLAN DE TRABAJO, ¿seguirá funcionando este enfoque si el conjunto de datos se ve como el siguiente?

WORKNOUBICACIÓNPLAN DE TRABAJOESTADOFECHAFECHA DE CIERRE ANTERIOR
1234AB-12E1001ABRIR01/02/22??
4321AB-12E2001CERRADO01/01/22
5678AB-12E1001CERRADO01/11/21
8765AB-12E2001 CERRADO 01/01/21
2345CD-34E1001ABRIR05/06/22??
6789CD-34E1001CERRADO01/05/21

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)