Find Max value, then subtract based on several conditions

rca

Board Regular
Joined
Mar 1, 2005
Messages
182
Hi All,

I have the following data set:

ID Sequence Type Time
R0000039 0 Manual 03:11:45.014
R0000039 1 Manual 03:11:45.018
R0000039 2 Manual 03:11:45.441
R0000059 0 Manual 03:14:33.857
R0000059 1 Manual 03:14:33.860
R0000059 2 Manual 03:14:33.868
R0000073 0 Internal 03:17:21.007
R0000073 1 Internal 03:17:21.010
R0000073 2 Internal 03:17:21.051
R0000165 0 Automatic 03:32:31.845
R0000165 1 Automatic 03:32:31.850
R0000165 2 Automatic 03:32:34.957

I'm interested in creating a separate column that:
a) looks up the ID (column A)
b) for each unique ID, finds the largest Sequence #
c) takes the Time for the largest Sequence #
d) subtracts the Time found in step "c" from the Time corresponding to the smallest Sequence number for that given ID

For example, the R0000039 ID would be 03:11:45.441 - 03:11:45.014, or 427 milliseconds.

I've tried to use MAXIFS(), but that didn't seem to work.

Any ideas on how to tackle this (either with VBA or a formula)? Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Someone else might have a more elegant solution, but here's my first attempt. I'm not sure about your entire dataset, so this might not work if you have multiple sets of the same ID in different sections of the data. This solution will only work if there is one ID set and if it always starts with 0.


Book1
ABCDE
1IDSequenceTypeTime
2R00000390Manual03:11:45.014
3R00000391Manual03:11:45.018
4R00000392Manual03:11:45.441427
5R00000590Manual03:14:33.857
6R00000591Manual03:14:33.860
7R00000592Manual03:14:33.86811
8R00000730Internal03:17:21.007
9R00000731Internal03:17:21.010
10R00000732Internal03:17:21.05144
11R00001650Automatic03:32:31.845
12R00001651Automatic03:32:31.850
13R00001652Automatic03:32:34.9573112
Sheet1
Cell Formulas
RangeFormula
E4=IF(AND(A4<>A5,A4=A3),(D4-INDEX(A:D,MATCH(A4,A:A,0),4))*86400000,"")
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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