Sum Duration with Criteria Between Times

Sully_T

New Member
Joined
Jun 13, 2020
Messages
6
Office Version
  1. 2010
Platform
  1. Windows
Hi All,

I usually think with enough googling and time I can my head round most issues but this one has me a bit stumped.

I have a log of recording status On/Off (could have other states too) with the start and end time. E:G

I would like to Sum the total time 'ON' during the interval in column A and B -
With just one time period i.e 8:00-9:00 I can do it on the lines in the log by making an adjustments to the start and end time based on the criteria, I suppose I could have a column for each period with an upper and lower criteria for each column...but that seems a messy solution.

So for example in the data below C4 = 00:42 C5 = 00:30 as it is only on for 30min between 9:00-10:00

Sum Times.xlsx
ABCDEFGH
1Interval01:00
2StatusAc StartAc EndDuration
3Start EndDuration OnON08:1508:5700:42
408:0009:00OFF08:5709:3000:33
509:0010:00ON09:3010:5001:20
610:0011:00OFF10:5011:1000:20
711:0012:00ON11:1012:0000:50
812:0013:00OFF12:0013:0001:00
913:0014:00ON13:0018:0005:00
1014:0015:00
1115:0016:00
1216:0017:00
1317:0018:00
Sheet1 (3)


Any help or pointers in the right direction would be greatly appreciated

Many thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Welcome to the forum,

If you can alter the table or create a new one, with just the "ON"times, then this appears to work

=MIN(C4,INDEX($H$3:$H$6,MATCH(C4,$G$3:$G$6,1)))-MAX(B4,INDEX($G$3:$G$6,MATCH(C4,$G$3:$G$6),1))

1592055056873.png
 
Upvote 0
This one appears to work using your table as it is

=MIN(C4,INDEX($H$3:$H$9,MATCH(C4,IF($F$3:$F$9="ON",$G$3:$G$9),1)))-MAX(B4,INDEX($G$3:$G$9,MATCH(C4,IF($F$3:$F$9="ON",$G$3:$G$9),1)))

Enter as an array using Ctrl, Shift & Enter

1592055497909.png
 
Upvote 0
Here's another method for you to try. With the example provided both give the same results, but I think that there may be differences if the times in columns F and G overlap, e.g. if you were summarising data for multiple people.

Book2
ABCDEFGH
1Interval01:00:00
2StatusAc StartAc EndDuration
3Start EndDuration OnON08:15:0008:57:0000:42:00
408:00:0009:00:0000:42:00OFF08:57:0009:30:0000:33:00
509:00:0010:00:0000:30:00ON09:30:0010:50:0001:20:00
610:00:0011:00:0000:50:00OFF10:50:0011:10:0000:20:00
711:00:0012:00:0000:50:00ON11:10:0012:00:0000:50:00
812:00:0013:00:0000:00:00OFF12:00:0013:00:0001:00:00
913:00:0014:00:0001:00:00ON13:00:0018:00:0005:00:00
1014:00:0015:00:0001:00:00
1115:00:0016:00:0001:00:00
1216:00:0017:00:0001:00:00
1317:00:0018:00:0001:00:00
Sheet1
Cell Formulas
RangeFormula
F4:F9F4=G3
H3:H9H3=G3-F3
C4:C13C4=SUM(IF($E$3:$E$13="ON",IF($G$3:$G$13>A4,IF($F$3:$F$13<B4,IF($G$3:$G$13>B4,B4,$G$3:$G$13)-IF($F$3:$F$13<A4,A4,$F$3:$F$13)))))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Solution
Thank you, I will bear that in mind and have a play with that too :)
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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