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
omarevp
Helper II
Helper II

Calcular duración entre 2 fechas obtenidas en la misma columna

Buen día a todos, necesito comparar una columna consigo misma, con el fin de calcular duración en hh:mm:ss. Acá explico lo que necesito:

 

Tengo una bd con registros de horas de conducción, horas de trabajo y horas de descanso por cada conductor, la bd registra cada actividad por separado de la siguiente forma, con un registro de Fecha y hora (FechaHora):

 

Captura.PNG 

 

 

Si yo coloco esto en la vista de informe y en visual de tabla, puedo darle este formato para mostrar más o menos lo que deseo:

Captura1.PNG
En esta tabla lo que hice fue tomar el mismo valor del campo FechaHora 2 veces en la misma tabla, uno mostrando la Primera FechaHora (*) del día y otro tomando la Última FechaHora (**) del mismo día, con un campo adicional que muestra solo la fecha con el fin de que separe fecha a fecha. Ahora bien, deseo calcular la diferencia de horas (Horas Diff) entre la FechaHora fin del día anterior y la FechaHora inicio del dia siguiente. Entendiendo que ambos datos salen de la misma columna. Acá grafico lo que necesito que aparezca, y que sea filtrable por conductor:

Captura2.PNG

Espero haberme explicado ya que sé que es un poco confuso, necesito la diferencia de horas entre la última fechahora registrada de un día y la primera fechahora registrada del día siguiente. Repito, todo eso sale del mismo campo llamado FechaHora.

 

Gracias por adelantado!

1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

Hi @omarevp,

Based on my test, you could refer to below steps:

Sample data:

1.PNG

Create two measures:

Measure = RANKX(ALL(Table1),FIRSTNONBLANK('Table1'[Date],'Table1'[Date]),,ASC,Dense)
Measure 2 = var a=[Measure]-1
return IF('Table1'[Measure]=1,BLANK(),CALCULATE(MAX('Table1'[*]))-CALCULATE(MAX('Table1'[**]),FILTER(ALL('Table1'),'Table1'[Measure]=a)))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

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

2 REPLIES 2
v-danhe-msft
Employee
Employee

Hi @omarevp,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Employee
Employee

Hi @omarevp,

Based on my test, you could refer to below steps:

Sample data:

1.PNG

Create two measures:

Measure = RANKX(ALL(Table1),FIRSTNONBLANK('Table1'[Date],'Table1'[Date]),,ASC,Dense)
Measure 2 = var a=[Measure]-1
return IF('Table1'[Measure]=1,BLANK(),CALCULATE(MAX('Table1'[*]))-CALCULATE(MAX('Table1'[**]),FILTER(ALL('Table1'),'Table1'[Measure]=a)))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
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.