Calculating the time elapsed between events that vary based on different cell criteria.

mhighland

New Member
Joined
Oct 11, 2017
Messages
13
I'm working with the following table:

EVENTIDPAGESTATUSTYPEJOBIDTIMESTAMPTime Elapsed: DaysTime Elapsed: Hours
49239521SchedulerCreatedPrivate6622643Wednesday, June 28, 2017UNDEFINEDUNDEFINED
49239522SchedulerNewAssigned6622643Wednesday, July 5, 2017UNDEFINEDUNDEFINED
50682764ShopperIncompleteSubmitted6622643Thursday, September 21, 2017UNDEFINEDUNDEFINED
50682775ShopperCompletedSubmitted6622643Thursday, September 21, 201703:10:29UNDEFINED
ReviewerIncompleteSubmitted6622643Monday, September 25, 2017UNDEFINED03:10:29:13
50725746ReviewerCompletedSubmitted6622643Monday, September 25, 201700:22:15UNDEFINED
50746671ReviewerFinalizedSubmitted6622643Tuesday, September 26, 2017UNDEFINEDUNDEFINED
50752728Locked6622643Tuesday, September 26, 2017UNDEFINEDUNDEFINED
49267081SchedulerCreatedPrivate6630464Wednesday, June 28, 2017UNDEFINEDUNDEFINED
49267082SchedulerNewAssigned6630464Friday, July 7, 2017UNDEFINEDUNDEFINED
50335478ShopperIncompleteSubmitted6630464Monday, September 4, 2017UNDEFINEDUNDEFINED
50446072ShopperIncompleteSubmitted6630464Saturday, September 9, 2017UNDEFINEDUNDEFINED
50446074ShopperCompletedSubmitted6630464Saturday, September 9, 201702:02:47UNDEFINED
50471615ReviewerFinalizedSubmitted6630464Monday, September 11, 2017UNDEFINED02:02:47:54
50473794Locked6630464Monday, September 11, 2017UNDEFINEDUNDEFINED

<tbody>
</tbody>

<tbody>
</tbody>

The TIMESTAMP column was in the format of dd:mm:yy hh:mm (there are several spaces between the date and the time) but I converted it to the Long Date format so I could calculate the difference between two dates based on specific criteria. I did not think it would work otherwise.

Initially, I wanted to know the amount of time elapsed between each time a "Shopper" (Column "Page") placed a report in "Completed (Column "Status") and a "Reviewer" (Column "Page") changed the status of the report. Since it was always the "Reviewer" that made the next action, the "Reviewer" is always in the row immediately after the row where the "Shopper" put a report in "Completed." Thus, I was able to use the following formula to correctly calculate the amount of time elapsed between the two events:

=IF(ISERROR(IF(AND($B5="Shopper", $C5="Completed"),$I6-$I5,IF(AND($B5="", $C5=""),$I6-$I5,"UNDEFINED"))),"",(IF(AND($B5="Shopper", $C5="Completed"),$I6-$I5,IF(AND($B5="", $C5=""),$I6-$I5,"UNDEFINED"))))

(Note: the cell references, ($B5="Shopper", $C5="Completed"), do not necessarily match up with the table excerpt above; they are merely illustrative.)

The result/output of the formula is in the "Time Elapsed: Hours" Column. However, the date stamp is modified to show days, hours, minutes, seconds; (dd:hh:mm:ss), so it is not actually the number of hours that have elapsed, it the the number of days, hours, minutes, and seconds that have elapsed.

My question is whether there is a way to modify the formula above so that it retrieves the time elapsed between when a "Shopper" puts a report in "Completed" and when the "Reviewer" completes any action whatsoever? For example, in the chart below, would it be possible to have a formula that calculates the time elapsed between the first event (50682775) and the second event (50722162) as well as between the first event (50682775) and the third event (50725746)?

50682775ShopperCompleted
50722162ReviewerIncomplete
50725746ReviewerCompleted

<tbody>
</tbody>

There are seven different actions that the "Reviewer" can take.

Ideally, the formula could be copied down the entire sheet.

I can provide clarification where needed, but I hope this is enough to get us started.

I appreciate any help that you can provide.
 
How's this...

EVENTIDPAGESTATUSTYPEJOBIDTIMESTAMPTime Elapsed: DaysTime Elapsed: Hours
49239521SchedulerCreatedPrivate662264328/06/17 06:56:00
49239522SchedulerNewAssigned662264305/07/17 21:42:00
50682764ShopperIncompleteSubmitted662264321/09/17 19:21:00
50682775ShopperCompletedSubmitted662264321/09/17 19:22:0003:10:30
50722162ReviewerIncompleteSubmitted662264325/09/17 05:52:0003:10:30:00
50725746ReviewerCompletedSubmitted662264325/09/17 09:19:0003:13:57:00
50746671ReviewerFinalizedSubmitted662264326/09/17 07:34:0004:12:12:00
50752728Locked662264326/09/17 12:19:0004:16:57:00
49267081SchedulerCreatedPrivate663046428/06/17 06:56:00
49267082SchedulerNewAssigned663046407/07/17 06:48:00
50335478ShopperIncompleteSubmitted663046409/04/17 09:25:00
50446072ShopperIncompleteSubmitted663046409/09/17 00:13:00
50446074ShopperCompletedSubmitted663046409/09/17 00:14:0001:02:47
50471615ReviewerFinalizedSubmitted663046409/11/17 03:01:0001:02:47:00
50473794Locked663046409/11/17 06:12:0001:05:58:00

<tbody>
</tbody>


The downside of these formulae is that you will need a blank row below your header and do not drag the formula into the blank row. So row 3 will contain your first row of data.

Put this into F3 and drag down.

=IF(AND(B3="Shopper", C3="Completed"),I4-I3,IF(AND(B3="", C3=""),I4-I3,""))

Put this into G3 and drag down

=IF(H3<>H2,"",IF(J2< >"",J2,IF(K2<>"",K2+I3-I2,"")))

You may notice I have changed the UNDEFINED to be blank as I thought it looked neater and was quicker to type but feel free to change it back.


OK, I understand the first formula and was able to successfully apply to my workbook. However, the second equation prompts an error message says there is a problem with the formula and suggests it be corrected to "=IF(H3<>H2),"",IF(J2<"",J2,IF(K2<>"",K2+I3-I2,")))

However, I think this might be because our column letters/references might not be aligned.

So long as i have a working formula, I can identify the cells each element refers to. Thus, I can reverse engineer the formula to fit my original worksheet.

So to simplify and make sure we're on the same page, let's work from this table with Column letters "A" through "H," as in the table below.

A
BCD
EFGH
EVENTIDPAGESTATUSTYPEJOBIDTIMESTAMPTIME ELAPSED 1TIME ELAPSED 2
49239521SchedulerCreatedPrivate66226436/28/17 06:56
49239522SchedulerNewAssigned66226437/5/17 21:42
50682764ShopperIncompleteSubmitted66226439/21/17 19:21
50682775ShopperCompletedSubmitted66226439/21/17 19:223.436956019
50722162ReviewerIncompleteSubmitted66226439/25/17 05:52
50725746ReviewerCompletedSubmitted66226439/25/17 09:19
50746671ReviewerFinalizedSubmitted66226439/26/17 07:34
50752728Locked66226439/26/17 12:19
49267081SchedulerCreatedPrivate66304646/28/17 06:56
49267082SchedulerNewAssigned66304647/7/17 06:48
50335478ShopperIncompleteSubmitted66304649/4/17 09:25
50446072ShopperIncompleteSubmitted66304649/9/17 00:13
50446074ShopperCompletedSubmitted66304649/9/17 00:142.116597222
50471615ReviewerFinalizedSubmitted66304649/11/17 03:01
50473794Locked66304649/11/17 06:12

<colgroup><col><col><col><col><col><col><col span="2"></colgroup><tbody>
</tbody>

The first "row" in the table above is not supposed to be a row—I just wanted to clarify the correct Column references.

I added a blank row between rows "1" and "2" so that the data now start in row "3". I copied your first formula in cell "G3", instead of "F3", as instructed, and copied down the page. "=IF(AND(B3="Shopper", C3="Completed"),I4-I3,IF(AND(B3="", C3=""),I4-I3,""))"

The results I got are in Column "G".

Obviously your second equation will not work with the table above as it is currently written, so that is what I want to clarify.

I assume that, in its current configuration, the second equation will go in Column "H," correct? If so, how should it be modified to function as it should? I see in the table you pasted above that it appears to be working correctly, I'm just having trouble duplicating.

Thank you for your help with this, I think we're almost there.
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I'm sorry. I initially seem to have told you to put the formula into the wrongs cells. I was supposed to say drag down from J3 and K3! I'm going to blame it on the time of day!

Using your original layout where jobid is H, the formulae literally translate as follows:

Elapsed days J3=IF(AND(B3="Shopper", C3="Completed"),I4-I3,IF(AND(B3="", C3=""),I4-I3,""))

=IF(AND(B3="Shopper", C3="Completed"),
If B on this row is shopper and C on this row is completed

I4-I3,
then find the difference between the timestamp on the row below and this row's timestamp.

IF(AND(B3="", C3=""),I4-I3,""))
If this row's B and C are blank then also find the difference between the timestamp on the row below and this row's timestamp.

(To be honest, I'm not even sure you need this as J3=IF(AND(B3="Shopper", C3="Completed"),I4-I3,"") does the same thing but then I don't have access to all of your data. In fact I'm not even sure of the necessity of this column, to me, it seems redundant but it's your prerogative. If you agree then go straight to the bottom of this post.)

Elapsed hours K3=IF(H3 < > H2,"",IF(J2 < > "",J2,IF(K2 < > "",K2+I3-I2,"")))

=IF(H3 < > H2,
If this row's jobid is different to the jobid above

"",
then be a blank cell.

IF(J2 < > "",
If the elapsed days cell on the row above is not blank

J2,
then show the same value as elapsed days from the row above.

IF(K2 < > "",
If the elapsed hours row above is not blank

K2+I3-I2,
then add to elapsed hours on the row above to the difference between timestamp of this row and the above row.

"")))
Otherwise, be blank.

As mentioned further up I have another suggestion...

Delete column J Elapsed days. Elapsed hours is now column J.

J3
Code:
=IF(H3<>H2,"",IF(AND(B2="shopper",C2="completed"),I3-I2,IF(J2<>"",J2+I3-I2,"")))

Sorry about all the spaces.
 
Last edited:
Upvote 0
If you don't want there to be a time showing when it's been locked then add IF(C3="locked","", at the beginning and a closing bracket at the very end.

i.e.
Code:
[COLOR=#333333]=IF(C3="locked","",IF(H3<>H2,"",IF(AND(B2="shopper",C2="completed"),I3-I2,IF(J2<>"",J2+I3-I2,""))))[/COLOR]

I'm sure you know how to format the cells but if not:
Select the entire row J. Right click | format cells | custom | Type: dd:hh:mm:ss | OK
 
Upvote 0
If you don't want there to be a time showing when it's been locked then add IF(C3="locked","", at the beginning and a closing bracket at the very end.

i.e.
Code:
[COLOR=#333333]=IF(C3="locked","",IF(H3<>H2,"",IF(AND(B2="shopper",C2="completed"),I3-I2,IF(J2<>"",J2+I3-I2,""))))[/COLOR]

I'm sure you know how to format the cells but if not:
Select the entire row J. Right click | format cells | custom | Type: dd:hh:mm:ss | OK

Awesome! This last formula works exactly how I need. Everything you mentioned in the previous post made perfect sense, and I agreed that it was best to delete Column "J." I also am really happy that you provided an option to not calculate values for reports in "Locked" status—it is distracting and isn't needed. I was toying around with the syntax of the formula trying to add in this conditional, but I never thought to put it at the beginning. I tried embedding it in the second, and then the third, "IF" statements to no avail.

Anyway, here is the result I got, along with some conditional formatting I added to highlight the any time that is more than 32 hours past the time a shopper put a report in "Completed" status.

I've redacted all the sensitive information in the worksheet:

EVENTID
PAGESTATUSTYPEWHOIDFIRSTNAMELASTNAME
JOBIDTIMESTAMPCLIENTIDCLIENTNAMESURVEYIDSURVEYNAMELOCCITYCOUNTRYNAMEAREACODETIME ELAPSED
49239521SchedulerCreatedPrivate17675466226436/28/17 06:56272517982
49239522SchedulerNewAssigned17675466226437/5/17 21:42272517982
50682764ShopperIncompleteSubmitted89146166226439/21/17 19:21272517982
50682775ShopperCompletedSubmitted89146166226439/21/17 19:22272517982
50722162ReviewerIncompleteSubmitted18923866226439/25/17 05:522725179823.436956019
50725746ReviewerCompletedSubmitted17675466226439/25/17 09:192725179823.580729167
50746671ReviewerFinalizedSubmitted18923866226439/26/17 07:342725179824.507962963
50752728Locked10906766226439/26/17 12:19272517982
49267081SchedulerCreatedPrivate19050266304646/28/17 06:56272517982
49267082SchedulerNewAssigned19050266304647/7/17 06:48272517982
50335478ShopperIncompleteSubmitted39417666304649/4/17 09:25272517982
50446072ShopperIncompleteSubmitted39417666304649/9/17 00:13272517982
50446074ShopperCompletedSubmitted39417666304649/9/17 00:14272517982
50471615ReviewerFinalizedSubmitted17355466304649/11/17 03:012725179822.116597222
50473794Locked10906766304649/11/17 06:12272517982

<tbody>
</tbody>

And here's my final formula: =IF(C2="Locked","",IF(H2<>H1,"",IF(AND(B1="Shopper",C1="Completed"),I2-I1,IF(Q1<>"",Q1+I2-I1,""))))

Fortunately, there isn't a need for a blank row between the headings and the start of the data, so I've been able to turn this into a template that others can simply copy-paste data into and have everything calculate automatically.

I do know how to format the timestamp, but thank you for taking the time to show me anyway.

All questions above answered! Thank you so, so much for all your help. I truly appreciate it.

As I continue to improve my Excel skills, I will definitely pay it forward and help others as you have helped me.

One final question? Is there anything I should do to mark this question as solved/answered? I'm unsure of the protocol here.

Many thanks!
 
Upvote 0
No problem at all. I love this kind of stuff (my other half is a gamer in his spare time and I've now run out of spreadsheets I can create at work while he's playing so turned to the internet to occupy my time! Sad, I know, but I'm a numbers and logic gal.)

I actually don't know how to mark a post as solved but if we stop posting it will eventually disappear into the nether :)
 
Upvote 0

Forum statistics

Threads
1,215,679
Messages
6,126,186
Members
449,296
Latest member
tinneytwin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top