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
ljmanayon
Frequent Visitor

Calculating Time Difference

Hi,

 

Hope someone can help me on this, am a noob on this. Anyways, I just simply want to compute the time difference between "Serving" and "Done" Remarks.  Here's my sample data.

 

DateTimeService IDProductRemarks
Aug, 1 20218:00:00AMB001BillsNew Entry
Aug, 1 20218:05:00AMB001BillsServing
Aug, 1 20218:07:00AMB001BillsDone
Aug, 1 20218:10:00AMB002BillsNew Entry
Aug, 1 20218:15:00AMB002BillsServing
Aug, 1 20218:20:00AMB002BillsDone
Aug, 1 20218:30:00AMC001CargoNew Entry
Aug, 1 20218:32:00AMC001CargoServing
Aug, 1 20219:40:00AMC001CargoDone

 

This is the result that I want. I want the time difference reflects on the "Serving" Remarks.

DateTimeService IDProductRemarksProcessing Time
Aug, 1 20218:00:00AMB001BillsNew Entry 
Aug, 1 20218:05:00AMB001BillsServing2mins
Aug, 1 20218:07:00AMB001BillsDone 
Aug, 1 20218:10:00AMB002BillsNew Entry 
Aug, 1 20218:15:00AMB002BillsServing5mins
Aug, 1 20218:20:00AMB002BillsDone 
Aug, 1 20218:30:00AMC001CargoNew Entry 
Aug, 1 20218:32:00AMC001CargoServing8mins
Aug, 1 20219:40:00AMC001CargoDone 

 

Thank you in advance.

1 ACCEPTED SOLUTION

Hi @ljmanayon 

I've checked the file, you can try this

Result I want Test = 
    var _endtime=CALCULATE(MIN(test[Time]),FILTER(ALLEXCEPT('test',test[Branch],test[Date/Time],'test'[Service ID]),'test'[Remarks]="Done"))
    var _diff=DATEDIFF(MIN('test'[Time]),_endtime,MINUTE)
return IF(MIN('test'[Remarks])="Serving",_diff&"mins")

result

vxiaotang_0-1629857922997.png

besides, in your previous example, the format of Time is xx:xx:00, while in your file, the format is xx:xx:xx, so I didn't add seconds into Measure.

 

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

13 REPLIES 13
v-xiaotang
Community Support
Community Support

Hi @ljmanayon 

with measure, you can try this

MinutesTest1 = 
var _b=CALCULATE(MIN('Table'[Time]),FILTER(ALLEXCEPT('Table','Table'[Service ID]),'Table'[Remarks]="Done"))
return IF(MIN('Table'[Remarks])="Serving",DATEDIFF(MIN('Table'[Time]),_b,MINUTE))

or

MinutesTest2 = 
var _b=CALCULATE(MIN('Table'[Time]),FILTER(ALLEXCEPT('Table','Table'[Service ID]),'Table'[Remarks]="Done"))
return IF(MIN('Table'[Remarks])="Serving",FORMAT(MIN('Table'[Time])-_b,"hh:nn:ss"))

result

vxiaotang_0-1629354695617.png

 

Best Regards,

Community Support Team _Tang

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

Thanks for your patience, but still it gives me a negative results. 

Hi @ljmanayon 

not sure but check the order in your measure,  the first parameter is StartDate, the second parameter is enddate.

vxiaotang_0-1629786304210.png

vxiaotang_1-1629786622988.png

in my side, there‘s no negative result. if problem still not solved, please share your file and I'll check it later.

Looking forward to receiving your reply.

 

Best Regards,

Community Support Team _Tang

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

 

I did follow your solution, but I still get a negative results. 

Here's the sample data that I have. Thanks again for your patience.

 

https://docs.google.com/spreadsheets/d/1KDoTj5PgzmsFzfY61v8RGk3QMbwXJb0t/edit?usp=sharing&ouid=11128... 

 

Hi @ljmanayon 

I've checked the file, you can try this

Result I want Test = 
    var _endtime=CALCULATE(MIN(test[Time]),FILTER(ALLEXCEPT('test',test[Branch],test[Date/Time],'test'[Service ID]),'test'[Remarks]="Done"))
    var _diff=DATEDIFF(MIN('test'[Time]),_endtime,MINUTE)
return IF(MIN('test'[Remarks])="Serving",_diff&"mins")

result

vxiaotang_0-1629857922997.png

besides, in your previous example, the format of Time is xx:xx:00, while in your file, the format is xx:xx:xx, so I didn't add seconds into Measure.

 

 

Best Regards,

Community Support Team _Tang

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

Thank you for time and patience. Appreciate it a lot.

I'll try your solution as soon as I get home. 

Hi @ljmanayon 

Have you solved this problem? If yes, could you kindly accept the answer helpful as the solution (or kindly share your solution ). so the others can find it more quickly.
really appreciate!
Any question, please let me know. Looking forward to receiving your reply.


Best Regards,
Community Support Team _Tang

Thanks for your help @v-xiaotang . I tried your solution but the measure gives me a negative results e.g. -60, -38, etc., and the calculated column gives no result.

 

My bad probably, I forgot to fill-in more data on my sample table. This the actual table looks like.

 

BranchDateTimeService IDProductRemarksResult I want
Branch A8/13/218:00:00AMB001BillsNew Entry 
Branch A8/13/218:10:00AMB001BillsServing5mins
Branch A8/13/218:15:00AMB001BillsDone 
Branch A8/13/218:16:00AMC001CargoNew Entry 
Branch A8/13/218:20:00AMC001CargoServing10mins
Branch A8/13/218:30:00AMC001CargoDone 
Branch A8/13/218:35:00AMB002BillsNew Entry 
Branch A8/13/218:40:00AMB002BillsServing20mins
Branch A8/13/219:00:00AMB002BillsDone 

Hi @ljmanayon 

try this 

Result I want = 
    var _b=CALCULATE(MIN('TableNew'[Time]),FILTER(ALLEXCEPT('TableNew','Tablenew'[Service ID]),'TableNew'[Remarks]="Done"))
    var _diff=DATEDIFF(MIN('TableNew'[Time]),_b,MINUTE)
return IF(MIN('TableNew'[Remarks])="Serving",_diff&"mins")

result

vxiaotang_0-1629443708199.png

 

Best Regards,

Community Support Team _Tang

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

amitchandak
Super User
Super User

@ljmanayon make sure you have datetime column if not create one like

 

Date Time = [Date] + [Time]


New column =
var _max = maxx(filter(Table, [Service ID] = earlier([Service ID]) && [Remarks] = " New Entry"),[Date Time])
return
if( [Remarks] = "Serving", datediff([Date Time], _max,minute), blank())

 

 

if needed add date to it

 

New column =
var _max = maxx(filter(Table, [Service ID] = earlier([Service ID]) && [Date] = earlier([Date])  && [Remarks] = " New Entry"),[Date Time])
return
if( [Remarks] = "Serving", datediff([Date Time], _max,minute), blank())

@amitchandak Thanks for answering. However, it returns thousands e.g. 5878, 6485, etc.

@ljmanayon , Oh need one correction, My mistake

 

New column =
var _max = maxx(filter(Table, [Service ID] = earlier([Service ID]) &&  [Date Time] < earlier([Date Time]) && [Remarks] = " New Entry"),[Date Time])
return
if( [Remarks] = "Serving", datediff(_max,[Date Time], minute), blank())

 

Thanks your help but I got 0 results or blank. And the formula takes so much time to calculate, unfortunately. 

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.