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
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

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
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.