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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Cómo calcular la diferencia de horas entre dos fechas/horas teniendo en cuenta las horas de trabajo

¿Cómo puedo calcular la diferencia en horas (Minutos también si es posible) teniendo en cuenta que la hora de trabajo es:

A partir de las 9:00:00

A las 17:00:00

He buscado en línea, pero estos temas no responden a mis preguntas directamente.

He intentado utilizar la función DATEDIFF que funciona como medida, pero no sé cómo incluir sólo las horas de trabajo en este caso.

DATEDIFF( MIN(Incident.dataaanmk); MIN(Datwijzig); HORA)

Estoy usando MIN porque un incidente puede tener:

- Sólo 1 Dataaanmk

- Pero muchos Datwijzig (Sólo tomamos el primero).

Capture.PNG

Gracias.

4 REPLIES 4
V-pazhen-msft
Community Support
Community Support

@hasfour

No estoy seguro de su resultado esperado. Si desea calcular la diferencia entre dos veces en HH:MM:SS. Sólo puede crear una columna: columna á [Columna de tiempo1]-[Columna de tiempo2] y, a continuación, cambiar la nueva columna a tipo de tiempo.

example time difference.JPG

Paul Zheng
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

Greg_Deckler
Super User
Super User

Pruebe algo en la línea de:

mNetWorkDuration = 
// Get the start and end dates
VAR __dateStart = MAX([Date_Start])
VAR __dateEnd = MAX([Date_End])
// Calculate the Net Work Days between the start and end dates
VAR __NetWorkDays = COUNTX(FILTER(ADDCOLUMNS(CALENDAR(__dateStart,__dateEnd),"WeekDay",WEEKDAY([Date],2)),[WeekDay]<6),[Date])
// Set this to the start of the work day (7:30 AM)
VAR __startHour = TIME(7,30,0)
// Set this variable to the end of the work day (6:00 PM)
VAR __endHour = TIME(18,0,0)
// Calculate the duration of a full day, in this case in minutes
VAR __fullDayMinutes = DATEDIFF(__startHour,__endHour,MINUTE)
VAR __fullDays = IF(__NetWorkDays < 2,0,__NetWorkDays-2)
VAR __fullDaysDuration = __fullDays * __fullDayMinutes 
VAR __startDayHour = TIME(HOUR(__dateStart),MINUTE(__dateStart),SECOND(__dateStart))
VAR __startDayDuration = DATEDIFF(__startDayHour,__endHour,MINUTE)
VAR __endDayHour = TIME(HOUR(__dateEnd),MINUTE(__dateEnd),SECOND(__dateEnd))
VAR __endDayDuration = DATEDIFF(__startHour,__endDayHour,MINUTE)
RETURN  __fullDaysDuration + __startDayDuration + __endDayDuration

https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Duration/m-p/481543#M182


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler

Gracias por su respuesta.

He aplicado la medida, pero tarda demasiado en aplicarla cuando se usa en una tabla.

¿Funciona? ¿Cuánto tiempo es demasiado? Potencialmente podría ser optimizado de alguna manera.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors