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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors