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
iseni
New Member

Calculate duration within a timeslot

Hi I have a two datetime columns (starttime and endtime)

I would like a measure that calculate the duration in minutes between 08:00 -16:00

 

Example 

Startime: 1-1-2021 06:35 and endtime: 1-1-2021 15:00 -> result: 420

Startime: 1-1-2021 01:35 and endtime: 1-1-2021 7:33 -> result: 0

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@iseni ,

new column =

var _start =if(hour([Start_time]) <= 8 , date(year([Start_time]), Month([Start_time]),day([Start_time])) +time(8,0,0) , [Start_Time])
var _end =if(hour([end_time]) >= 16 , date(year([end_time]), Month([end_time]),day([end_time])) +time(16,0,0) , [end_time])

var _diff =diff(_start,_end, minute)
return if(_diff <0, 0, _diff)

View solution in original post

2 REPLIES 2
iseni
New Member

Thanks works perfect 🙂 

amitchandak
Super User
Super User

@iseni ,

new column =

var _start =if(hour([Start_time]) <= 8 , date(year([Start_time]), Month([Start_time]),day([Start_time])) +time(8,0,0) , [Start_Time])
var _end =if(hour([end_time]) >= 16 , date(year([end_time]), Month([end_time]),day([end_time])) +time(16,0,0) , [end_time])

var _diff =diff(_start,_end, minute)
return if(_diff <0, 0, _diff)

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.