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

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

Reply
Anonymous
Not applicable

Substract start time column from end time column based on date and sequence

Hello everyone,

 

I would like to subtract "start time" from "end time" based on date and sequence. 

we visit customers based on a given sequence within a certain day. I would like to calculate the time spent between customers. 

It will be= Start_Time-End_Time (Based on date column and sequence column)

 

DateCustomerVisiting_SequenceStart_TimeEnd_Time
10/22/2021a113:5613:59
10/22/2021b214:1014:20
10/22/2021c314:3114:44
10/22/2021d414:5014:55
10/22/2021e514:5915:09
10/22/2021f615:1615:20

 

This is the expected value I would like to get.

DateCustomerVisiting_SequenceStart_TimeEnd_Time
Expected_Value
10/22/2021a113:5613:59 
10/22/2021b214:1014:200:11
10/22/2021c314:3114:440:11
10/22/2021d414:5014:550:06
10/22/2021e514:5915:090:04
10/22/2021f615:1615:200:07
1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @Anonymous 

 

Try this:

Measure = 
var _Seq=MAX('Table'[Visiting_Sequence])
var _last_Seq=_Seq-1
var _endOfLast=CALCULATE(MAX('Table'[End_Time]),FILTER(ALL('Table'),'Table'[Visiting_Sequence]=_last_Seq))

var _result=IF(ISBLANK(_endOfLast),BLANK(),
FORMAT(MAX('Table'[Start_Time])-_endOfLast,"hh:mm")
)

return _result

Result:

vangzhengmsft_0-1635158740179.png

Please refer to the attachment below for details. Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-angzheng-msft
Community Support
Community Support

Hi, @Anonymous 

 

Try this:

Measure = 
var _Seq=MAX('Table'[Visiting_Sequence])
var _last_Seq=_Seq-1
var _endOfLast=CALCULATE(MAX('Table'[End_Time]),FILTER(ALL('Table'),'Table'[Visiting_Sequence]=_last_Seq))

var _result=IF(ISBLANK(_endOfLast),BLANK(),
FORMAT(MAX('Table'[Start_Time])-_endOfLast,"hh:mm")
)

return _result

Result:

vangzhengmsft_0-1635158740179.png

Please refer to the attachment below for details. Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Is it not

a new column =

datediff([end_time],[Start_time], second)+1

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
Anonymous
Not applicable

Thank you for your response
is it possible to include the sequence column to calculate? there are a lot of customers and a lot of sales reps. and the sequence on the table is kind of mixed up. the only thing that can be used to calculate is the date and the sequence number, for each sales reps.

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.