Forum Discussion
Calculating the time between two timestamps excluding break times
Hello all,
I hope you can help me, since I've searched a lot and couldn't find a solution for my particular problem.
My scenario is as follows: I have two timestamps which I need to calculate the difference in minutes BUT if either the creation or the end time is within the break time, I need to subtract the amount of minutes that were within the break time. The break time is from 11:30 to 12:00.
Example:
| Creation Date Time | Confirmation Date Time | Confirmation Duration | Desired Duration |
| 11:02:17 | 12:07:12 | 64 | 34 |
| 11:14:20 | 12:07:39 | 53 | 23 |
| 11:21:36 | 12:02:52 | 41 | 11 |
| 11:21:42 | 12:03:09 | 41 | 11 |
| 11:16:24 | 11:45:23 | 29 | 14 |
| 11:44:12 | 12:06:03 | 22 | 6 |
I hope there is a solution to my problem.
Many thanks in advance.
Tauer , First create a caluclated column for Total duration
TotalDuration = DATEDIFF([Creation Date Time], [Confirmation Date Time], MINUTE)
Then create a calculated column for break time adjustment
BreakStart = TIME(11, 30, 0)
BreakEnd = TIME(12, 0, 0)BreakMinutes =
VAR CreationTime = TIME(HOUR([Creation Date Time]), MINUTE([Creation Date Time]), SECOND([Creation Date Time]))
VAR ConfirmationTime = TIME(HOUR([Confirmation Date Time]), MINUTE([Confirmation Date Time]), SECOND([Confirmation Date Time]))
VAR BreakStartTime = BreakStart
VAR BreakEndTime = BreakEnd
VAR OverlapStart = MAX(BreakStartTime, CreationTime)
VAR OverlapEnd = MIN(BreakEndTime, ConfirmationTime)
VAR OverlapMinutes = DATEDIFF(OverlapStart, OverlapEnd, MINUTE)
RETURN
IF(OverlapStart < OverlapEnd, OverlapMinutes, 0)In the end create one more column for desired duration
DAX
DesiredDuration = [TotalDuration] - [BreakMinutes]
2 Replies
- bhanu_gautam
Super User
Tauer , First create a caluclated column for Total duration
TotalDuration = DATEDIFF([Creation Date Time], [Confirmation Date Time], MINUTE)
Then create a calculated column for break time adjustment
BreakStart = TIME(11, 30, 0)
BreakEnd = TIME(12, 0, 0)BreakMinutes =
VAR CreationTime = TIME(HOUR([Creation Date Time]), MINUTE([Creation Date Time]), SECOND([Creation Date Time]))
VAR ConfirmationTime = TIME(HOUR([Confirmation Date Time]), MINUTE([Confirmation Date Time]), SECOND([Confirmation Date Time]))
VAR BreakStartTime = BreakStart
VAR BreakEndTime = BreakEnd
VAR OverlapStart = MAX(BreakStartTime, CreationTime)
VAR OverlapEnd = MIN(BreakEndTime, ConfirmationTime)
VAR OverlapMinutes = DATEDIFF(OverlapStart, OverlapEnd, MINUTE)
RETURN
IF(OverlapStart < OverlapEnd, OverlapMinutes, 0)In the end create one more column for desired duration
DAX
DesiredDuration = [TotalDuration] - [BreakMinutes]- TauerNew Member
bhanu_gautam Thank you so much, that's exactly what I needed!!!