# Time Difference If Statement

#### RayClarke

##### New Member
Hi,

I am looking to calculate a time difference depending on the values in another column.
In the same way I can normally SumIF (if two values are the same) is there a way I can subtract IF?

In the example below, i want to find the difference between the 2 time stamps if the EventID is the same (i.e. how long the event lasted)
There will only ever be two identical eventID's, but they won't necessarily be one after the other on the sheet.

Line 38 All alarm list.xls
AB
1Date TimeEventID
22021-05-12 00:54:30{050A0E27-6095-4E71-9187-C6EFFC12C272}
32021-05-12 00:54:31{6E78EF9F-9294-4E5A-AA7E-D9360C0DBE54}
42021-05-12 00:54:40{6E78EF9F-9294-4E5A-AA7E-D9360C0DBE54}
52021-05-12 00:54:43{050A0E27-6095-4E71-9187-C6EFFC12C272}
72021-05-12 02:36:27{25D734D3-4F75-4FFC-B83B-FEE68FC1F80B}
82021-05-12 02:36:40{25D734D3-4F75-4FFC-B83B-FEE68FC1F80B}
102021-05-13 09:02:14{838879B0-B4D6-4DBF-A285-C9587135C9F9}
112021-05-13 09:02:14{9CFB062C-8E6E-4397-81EE-32942E00BD22}
122021-05-13 09:02:24{9CFB062C-8E6E-4397-81EE-32942E00BD22}
132021-05-13 09:02:27{838879B0-B4D6-4DBF-A285-C9587135C9F9}
Sheet4

Any help would be greatly appreciated.

Thanks,
Ray

### Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

#### Dave Patton

##### Well-known Member
try Aggregate or with 365 Max Filter Min Filter

Date and Time 2021.xlsm
ABC
1Date TimeEventID
212-05-21 00:54{050A0E27-6095-4E71-9187-C6EFFC12C272}00:00:13
10b
Cell Formulas
RangeFormula
C2C2=AGGREGATE(14,6,\$A\$2:\$A\$11/(\$B\$2:\$B\$11=B2),1)-AGGREGATE(15,6,\$A\$2:\$A\$11/(\$B\$2:\$B\$11=B2),1)

#### steve the fish

##### Well-known Member
Heres a couple:

=MAXIFS(A:A,B:B,B2)-MINIFS(A:A,B:B,B2)
=ABS(2*(AVERAGEIFS(A:A,B:B,B2)-A2))

#### RayClarke

##### New Member
try Aggregate or with 365 Max Filter Min Filter

Date and Time 2021.xlsm
ABC
1Date TimeEventID
212-05-21 00:54{050A0E27-6095-4E71-9187-C6EFFC12C272}00:00:13
10b
Cell Formulas
RangeFormula
C2C2=AGGREGATE(14,6,\$A\$2:\$A\$11/(\$B\$2:\$B\$11=B2),1)-AGGREGATE(15,6,\$A\$2:\$A\$11/(\$B\$2:\$B\$11=B2),1)
This worked! Thank you very much. Aggregate isn't something i've used before, it's very useful.

Replies
1
Views
361
Replies
3
Views
89
Replies
5
Views
170
Replies
3
Views
135
Replies
6
Views
310

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,152,235
Messages
5,768,951
Members
425,507
Latest member
AndreaWorkPlace

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

### Which adblocker are you using?

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

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