Don't miss your chance to take exam DP-600 or DP-700 on us!
Request nowLearn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hi,
How do you calculate for each carer_id, the difference in hours and minutes between their last shift & the start of their next shift on the following day?
Below, carer_id 78315, their last shift on 18/11/2021 is 20:40
&
their first shift the next day 19//11/2021 is 08:00
so result should be 11hrs 20 mins.
Solved! Go to Solution.
Hi, @Qotsa
Duration =
VAR n1 =
CALCULATE (
MIN ( 'Table'[Sched_Start] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date] ) )
)
VAR n2 = [date] - 1
VAR n3 =
CALCULATE (
MAX ( 'Table'[Sched_Finsh] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date2] ) )
)
RETURN
IF (
n3 = BLANK (),
BLANK (),
IF ( [Sched_Start] = n1, ( [date] + n1 ) - ( n2 + n3 ), BLANK () )
)
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Qotsa
Your problem can be solved by adding several calculation columns. You can try the following methods.
MIN =
CALCULATE (
MIN ( 'Table'[Sched_Start] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date] ) )
)
date2 = [date]-1MAX =
CALCULATE (
MAX ( 'Table'[Sched_Finsh] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date2] ) )
)
Duration =
IF ( [MAX] = BLANK (), BLANK (), ( [date] + [MIN] ) - ( [date2] + [MAX] ) )
The calculation column is the decomposition step, which is convenient for you to understand.
It can be solved directly by this formula. There is no need to add a calculated column.
Duration2 =
VAR n1 =
CALCULATE (
MIN ( 'Table'[Sched_Start] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date] ) )
)
VAR n2 = [date] - 1
VAR n3 =
CALCULATE (
MAX ( 'Table'[Sched_Finsh] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date2] ) )
)
RETURN
IF ( n3 = BLANK (), BLANK (), ( [date] + n1 ) - ( n2 + n3 ) )
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@v-zhangti Thanks very much, that works. How could I remove the repeating times so it only shows the duration once ?
Hi, @Qotsa
Duration =
VAR n1 =
CALCULATE (
MIN ( 'Table'[Sched_Start] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date] ) )
)
VAR n2 = [date] - 1
VAR n3 =
CALCULATE (
MAX ( 'Table'[Sched_Finsh] ),
FILTER ( 'Table', [date] = EARLIER ( 'Table'[date2] ) )
)
RETURN
IF (
n3 = BLANK (),
BLANK (),
IF ( [Sched_Start] = n1, ( [date] + n1 ) - ( n2 + n3 ), BLANK () )
)
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Fantastic. Thanks again.
@Qotsa , a new column
var _datetime = [Date]+ [Sched_finish]
var _max = maxx(filter(Table, [Carter_id] = earlier([Carter_id]) && _datetime <[Date] +[Sched_start]),[Date]+ [Sched_finish])
return
[Date] +[Sched_start] - _max
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 55 | |
| 49 | |
| 33 | |
| 16 | |
| 15 |
| User | Count |
|---|---|
| 85 | |
| 70 | |
| 38 | |
| 28 | |
| 25 |