Find closest number based on string

robford16

New Member
Joined
Jan 11, 2016
Messages
1
Hello,

I am trying to figure out a way to find the closest number to another number. Here is what my spreadsheet looks like:

Rowtime stampevent #unitunit status
1
1420089320

<tbody>
</tbody>
1ehold
2
1420089448

<tbody>
</tbody>
1earrive
314200895001eavailable
4
1420089653

<tbody>
</tbody>
2mhold
5
1420090098

<tbody>
</tbody>
2marrive
6
1420090377

<tbody>
</tbody>
2mhold
7
1420090400

<tbody>
</tbody>
2mhold
8
1420090412

<tbody>
</tbody>
2mavailable

<tbody>
</tbody>


I am trying to find the average time between all instances of arrive-hold and arrive-available for each unit (average time on hold for each unit for each event). For example, I would want to calculate the difference between row 3 and 4, and row 5 (because it is the first hold instance) and 7. Sometimes units have multiple/varying amounts of hold time stamps before they are marked arrive (as in rows 5 and 6). So the formula would have to look for the first hold time stamp, then look for the next closest arrive or available time stamp AND make sure the unit and event number match.

My timestamps are in epoch seconds. I am using Excel 2010 64-bit.

Thank you!!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi

I'm not sure I understand what you're looking for, but hopefully the following will help you solve your problem. On the basis you want a 'wait time' for each hold period, the way I'd solve this is to use the following logic in a formula for each row:

1. Is the status hold? If not, don't return anything. If so, continue.
2. Find the minimum time that meets all of my criteria, namely (a) that the time is after the current time, (b) that the event matches, and (c) that the unit matches.
3. Subtract the hold timestamp from this timestamp to find the time difference.

Then I would add a pivot table that aggregated the values on a unit basis.

If your timestamps are in B2:B9, your event is in C2:C9, your unit is in D2:D9 and your status is in E2:E9, then in F2 write the following and execute using control+shift+enter:

Minimum time after:
Code:
=IF(E2<>"hold","",MIN(IF(C2=$C$2:$C$9,IF(D2=$D$2:$D$9,IF(B2<$B$2:$B$9,$B$2:$B$9,9E+37)))))
Time difference between minimum time after and current timestamp (you can consolidate these two formulas into a single formula if you prefer):
Code:
=IF(F2="","",F2-B2)

Hope that helps - note that if there is no status following the hold it will return a very wacky result.

Mackers
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,769
Members
448,991
Latest member
Hanakoro

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