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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
CupidC
Helper II
Helper II

Calculating Time between two time in the same date

Hi All

 

I have encountered an issue that I need assistance with. Here is the problem:

 

I would like to calculate the idle time between a salesperson serving customers.

 

For instance, let's consider John on 26/06/2023. He served two customers, the first from 10:15 am to 11:15 am, and then he started serving another customer at 11:30 am. I am uncertain about which DAX function to use in order to calculate the 15-minute idle time between the two customer interactions.

 

Initially, I thought about using the RANKX function, but I'm unsure about the subsequent steps. Any help would be greatly appreciated.

 

Thank you in advance for your assistance.

 

CupidC_0-1687765603389.png

 

3 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@CupidC 

you can try this

Column = 
VAR _last=maxx(FILTER('Table','Table'[Sales Person]=EARLIER('Table'[Sales Person])&&'Table'[Date]=EARLIER('Table'[Date])&&'Table'[From]<EARLIER('Table'[From])),'Table'[To])
return if(ISBLANK(_last),blank(),DATEDIFF(_last,'Table'[From],MINUTE))

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Hi @ryan_mayu

Firstly, thank you so much for your help. You are truly amazing!

I have a follow-up question: Does the calculation have to be performed as a calculated column, or is there a way to write it as a measure?

Additionally, I attempted to substitute the formula using a Variable instead of "earlier," but I encountered some issues and it didn't work. Do you happen to know a solution to this?

 

Thank you once again for your incredible support.

 

Cupid 🙂

View solution in original post

@CupidC 

if you want to create a measure , you can try this

Measure = 
VAR _last=maxx(FILTER(all('Table'),'Table'[Sales Person]=max('Table'[Sales Person])&&'Table'[Date]=max('Table'[Date])&&'Table'[From]<max('Table'[From])),'Table'[To])
return DATEDIFF(_last,max('Table'[From]),MINUTE)+0

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ryan_mayu
Super User
Super User

@CupidC 

you can try this

Column = 
VAR _last=maxx(FILTER('Table','Table'[Sales Person]=EARLIER('Table'[Sales Person])&&'Table'[Date]=EARLIER('Table'[Date])&&'Table'[From]<EARLIER('Table'[From])),'Table'[To])
return if(ISBLANK(_last),blank(),DATEDIFF(_last,'Table'[From],MINUTE))

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ryan_mayu

Firstly, thank you so much for your help. You are truly amazing!

I have a follow-up question: Does the calculation have to be performed as a calculated column, or is there a way to write it as a measure?

Additionally, I attempted to substitute the formula using a Variable instead of "earlier," but I encountered some issues and it didn't work. Do you happen to know a solution to this?

 

Thank you once again for your incredible support.

 

Cupid 🙂

@CupidC 

if you want to create a measure , you can try this

Measure = 
VAR _last=maxx(FILTER(all('Table'),'Table'[Sales Person]=max('Table'[Sales Person])&&'Table'[Date]=max('Table'[Date])&&'Table'[From]<max('Table'[From])),'Table'[To])
return DATEDIFF(_last,max('Table'[From]),MINUTE)+0

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.