SUMIF with 3 criteria between dates

picklefactory

Well-known Member
Joined
Jan 28, 2005
Messages
508
Office Version
  1. 365
Platform
  1. Windows
Hi folks
Frying my brain with this. My head says it should be simple....unfortunately it seems to be me that's simple :mad:
I have some software that logs machine activity and creates a lot of data that I need to summarise, very small snapshot enclosed. Cols A to E are what comes from the software and it tracks machine status over entire 24 hour periods, some of which time the machine is unmanned and not running. I'm trying to extract the time spent running during the two shift periods (Early and Late) where it is manned, so in Cols K,L,O and P I have constructed shift start and end times for each day that the log has recorded and I simply want to sum the Mins from Col D where the start/end time in cols B & C fall between the start/end times in Cols K,L,O and P for each shift PLUS the LogID in Col E = 2 (Which is the log code for running). So I think 3 criteria, but every formula attempt I've tried so far has failed miserably. I know in this snapshot enclosed that the Early shift will show nothing, as the times fall outside of the window due to the log start/end times in this instance.
Is it simple and I'm just thick? It's not an array formula, is it?
Thanks


Excel 2010
ABCDEFGHIJKLMNOPQ
2IDStartTimeEndTimeMinsLogIDDateEarly StartEarly EndRunningLate StartLate EndRunning
335562210/08/2017 17:4010/08/2017 17:410.452Start Date10/08/201710/08/201710/08/2017 06:0010/08/2017 15:0010/08/2017 16:0010/08/2017 04:00
435562310/08/2017 17:4110/08/2017 17:410.382End Date08/09/201711/08/201711/08/2017 06:0011/08/2017 15:0011/08/2017 16:0011/08/2017 04:00
535562410/08/2017 17:4110/08/2017 17:410.181Early Start time06:0012/08/201712/08/2017 06:0012/08/2017 15:0012/08/2017 16:0012/08/2017 04:00
635562510/08/2017 17:4110/08/2017 17:420.422Early End time15:0013/08/201713/08/2017 06:0013/08/2017 15:0013/08/2017 16:0013/08/2017 04:00
735562610/08/2017 17:4210/08/2017 17:430.981Late Start time16:0014/08/201714/08/2017 06:0014/08/2017 15:0014/08/2017 16:0014/08/2017 04:00
835562710/08/2017 17:4310/08/2017 19:29106.021Late End time04:0015/08/201715/08/2017 06:0015/08/2017 15:0015/08/2017 16:0015/08/2017 04:00
935563010/08/2017 19:2910/08/2017 19:290.2116/08/201716/08/2017 06:0016/08/2017 15:0016/08/2017 16:0016/08/2017 04:00
1035563110/08/2017 19:2910/08/2017 19:300.78217/08/201717/08/2017 06:0017/08/2017 15:0017/08/2017 16:0017/08/2017 04:00
1001
Cell Formulas
RangeFormula
J3=I3
J4=IF(J3="","",IF(J3+1>($I$4+1),"",J3+1))
J5=IF(J4="","",IF(J4+1>($I$4+1),"",J4+1))
J6=IF(J5="","",IF(J5+1>($I$4+1),"",J5+1))
J7=IF(J6="","",IF(J6+1>($I$4+1),"",J6+1))
J8=IF(J7="","",IF(J7+1>($I$4+1),"",J7+1))
J9=IF(J8="","",IF(J8+1>($I$4+1),"",J8+1))
J10=IF(J9="","",IF(J9+1>($I$4+1),"",J9+1))
K3=IF(J3="","",J3+$I$5)
K4=IF(J4="","",J4+$I$5)
K5=IF(J5="","",J5+$I$5)
K6=IF(J6="","",J6+$I$5)
K7=IF(J7="","",J7+$I$5)
K8=IF(J8="","",J8+$I$5)
K9=IF(J9="","",J9+$I$5)
K10=IF(J10="","",J10+$I$5)
L3=IF(J3="","",J3+$I$6)
L4=IF(J4="","",J4+$I$6)
L5=IF(J5="","",J5+$I$6)
L6=IF(J6="","",J6+$I$6)
L7=IF(J7="","",J7+$I$6)
L8=IF(J8="","",J8+$I$6)
L9=IF(J9="","",J9+$I$6)
L10=IF(J10="","",J10+$I$6)
O3=IF(J3="","",J3+$I$7)
O4=IF(J4="","",J4+$I$7)
O5=IF(J5="","",J5+$I$7)
O6=IF(J6="","",J6+$I$7)
O7=IF(J7="","",J7+$I$7)
O8=IF(J8="","",J8+$I$7)
O9=IF(J9="","",J9+$I$7)
O10=IF(J10="","",J10+$I$7)
P3=IF(J3="","",J3+$I$8)
P4=IF(J4="","",J4+$I$8)
P5=IF(J5="","",J5+$I$8)
P6=IF(J6="","",J6+$I$8)
P7=IF(J7="","",J7+$I$8)
P8=IF(J8="","",J8+$I$8)
P9=IF(J9="","",J9+$I$8)
P10=IF(J10="","",J10+$I$8)
I3=INT(MIN(B:B))
I4=INT(MAX(B:B))
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
may be your inconsistent late start/end hrs caused the problem, I've amended late end from 10/08/2017 04:00 to 11/08/2017 04:00 etc


Excel 2013/2016
ABCDEFGHIJKLMNOPQR
1
2IDStartTimeEndTimeMinsLogIDDateEarly StartEarly EndRunningLate StartLate EndRunning
335562210/08/2017 17:4010/08/2017 17:410.452Start Date10/08/201710/08/201710/08/2017 06:0010/08/2017 15:00010/08/2017 16:0011/08/2017 04:002.03
435562310/08/2017 17:4110/08/2017 17:410.382End Date08/09/201711/08/201711/08/2017 06:0011/08/2017 15:0011/08/2017 16:0012/08/2017 04:00
535562410/08/2017 17:4110/08/2017 17:410.181Early Start time06:0012/08/201712/08/2017 06:0012/08/2017 15:0012/08/2017 16:0013/08/2017 04:00
635562510/08/2017 17:4110/08/2017 17:420.422Early End time15:0013/08/201713/08/2017 06:0013/08/2017 15:0013/08/2017 16:0014/08/2017 04:00
735562610/08/2017 17:4210/08/2017 17:430.981Late Start time16:0014/08/201714/08/2017 06:0014/08/2017 15:0014/08/2017 16:0015/08/2017 04:00
835562710/08/2017 17:4310/08/2017 19:29106.021Late End time04:0015/08/201715/08/2017 06:0015/08/2017 15:0015/08/2017 16:0016/08/2017 04:00
935563010/08/2017 19:2910/08/2017 19:290.2116/08/201716/08/2017 06:0016/08/2017 15:0016/08/2017 16:0017/08/2017 04:00
1035563110/08/2017 19:2910/08/2017 19:300.78217/08/201717/08/2017 06:0017/08/2017 15:0017/08/2017 16:0018/08/2017 04:00
Sheet1
Cell Formulas
RangeFormula
N3=SUMPRODUCT(--($F$3:$F$10=2),$E$3:$E$10,--($C$3:$C$10>=L3),--($D$3:$D$10<=M3))
R3=SUMPRODUCT(--($F$3:$F$10=2),$E$3:$E$10,--($C$3:$C$10>=P3),--($D$3:$D$10<=Q3))
 
Upvote 0
Thanks Alan
I had certainly missed my error in the Late End Date, thank you. However, it's still not working for me. I seem to have lost a column too. here is what I have now which is giving me a result in M3, which it shouldn't, the correct result in Q3, but when I click and drag the formula down, it doesn't work in the cells below.
What have I stuffed up now!!!



Excel 2010
ABCDEFGHIJKLMNOPQ
2IDStartTimeEndTimeMinsLogIDDateEarly StartEarly EndRunningLate StartLate EndRunning
335562210/08/2017 17:4010/08/2017 17:410.452Start Date10/08/201710/08/201710/08/2017 06:0010/08/2017 15:0017183110/08/2017 16:0011/08/2017 04:002.03
435562310/08/2017 17:4110/08/2017 17:410.382End Date08/09/201711/08/201711/08/2017 06:0011/08/2017 15:00011/08/2017 16:0012/08/2017 04:000
535562410/08/2017 17:4110/08/2017 17:410.181Early Start time06:0012/08/201712/08/2017 06:0012/08/2017 15:00012/08/2017 16:0013/08/2017 04:000
635562510/08/2017 17:4110/08/2017 17:420.422Early End time15:0013/08/201713/08/2017 06:0013/08/2017 15:00013/08/2017 16:0014/08/2017 04:000
735562610/08/2017 17:4210/08/2017 17:430.981Late Start time16:0014/08/201714/08/2017 06:0014/08/2017 15:00014/08/2017 16:0015/08/2017 04:000
835562710/08/2017 17:4310/08/2017 19:29106.021Late End time04:0015/08/201715/08/2017 06:0015/08/2017 15:00015/08/2017 16:0016/08/2017 04:000
935563010/08/2017 19:2910/08/2017 19:290.2116/08/201716/08/2017 06:0016/08/2017 15:00016/08/2017 16:0017/08/2017 04:000
1035563110/08/2017 19:2910/08/2017 19:300.78217/08/201717/08/2017 06:0017/08/2017 15:00017/08/2017 16:0018/08/2017 04:000
1001
Cell Formulas
RangeFormula
J3=I3
J4=IF(J3="","",IF(J3+1>($I$4+1),"",J3+1))
J5=IF(J4="","",IF(J4+1>($I$4+1),"",J4+1))
J6=IF(J5="","",IF(J5+1>($I$4+1),"",J5+1))
J7=IF(J6="","",IF(J6+1>($I$4+1),"",J6+1))
J8=IF(J7="","",IF(J7+1>($I$4+1),"",J7+1))
J9=IF(J8="","",IF(J8+1>($I$4+1),"",J8+1))
J10=IF(J9="","",IF(J9+1>($I$4+1),"",J9+1))
K3=IF(J3="","",J3+$I$5)
K4=IF(J4="","",J4+$I$5)
K5=IF(J5="","",J5+$I$5)
K6=IF(J6="","",J6+$I$5)
K7=IF(J7="","",J7+$I$5)
K8=IF(J8="","",J8+$I$5)
K9=IF(J9="","",J9+$I$5)
K10=IF(J10="","",J10+$I$5)
L3=IF(J3="","",J3+$I$6)
L4=IF(J4="","",J4+$I$6)
L5=IF(J5="","",J5+$I$6)
L6=IF(J6="","",J6+$I$6)
L7=IF(J7="","",J7+$I$6)
L8=IF(J8="","",J8+$I$6)
L9=IF(J9="","",J9+$I$6)
L10=IF(J10="","",J10+$I$6)
M3=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K3),--($D$3:$D$10<=L3))
M4=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K4),--($D$3:$D$10<=L4))
M5=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K5),--($D$3:$D$10<=L5))
M6=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K6),--($D$3:$D$10<=L6))
M7=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K7),--($D$3:$D$10<=L7))
M8=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K8),--($D$3:$D$10<=L8))
M9=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K9),--($D$3:$D$10<=L9))
M10=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K10),--($D$3:$D$10<=L10))
O3=IF(J3="","",J3+$I$7)
O4=IF(J4="","",J4+$I$7)
O5=IF(J5="","",J5+$I$7)
O6=IF(J6="","",J6+$I$7)
O7=IF(J7="","",J7+$I$7)
O8=IF(J8="","",J8+$I$7)
O9=IF(J9="","",J9+$I$7)
O10=IF(J10="","",J10+$I$7)
P3=IF(J3="","",(J3+1)+$I$8)
P4=IF(J4="","",(J4+1)+$I$8)
P5=IF(J5="","",(J5+1)+$I$8)
P6=IF(J6="","",(J6+1)+$I$8)
P7=IF(J7="","",(J7+1)+$I$8)
P8=IF(J8="","",(J8+1)+$I$8)
P9=IF(J9="","",(J9+1)+$I$8)
P10=IF(J10="","",(J10+1)+$I$8)
Q3=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O3),--($C$3:$C$10<=P3))
Q4=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O4),--($C$3:$C$10<=P4))
Q5=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O5),--($C$3:$C$10<=P5))
Q6=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O6),--($C$3:$C$10<=P6))
Q7=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O7),--($C$3:$C$10<=P7))
Q8=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O8),--($C$3:$C$10<=P8))
Q9=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O9),--($C$3:$C$10<=P9))
Q10=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=O10),--($C$3:$C$10<=P10))
I3=INT(MIN(B:B))
I4=INT(MAX(B:B))
 
Last edited:
Upvote 0
Apologies.....as expected....I'm an idiot. Obviously your formula only covered the range of cells I'd uploaded, once I changed the range to cover the entire log it works fine.
Thank you very much for your help.
 
Upvote 0
the formula in M3 etc are pointed t the wrong columns

=SUMPRODUCT(--($E$3:$E$10=2),$C$3:$C$10,--($B$3:$B$10>=K3),--($D$3:$D$10<=L3))

should read

=SUMPRODUCT(--($E$3:$E$10=2),$D$3:$D$10,--($B$3:$B$10>=K3),--($C$3:$C$10<=L3))
 
Upvote 0
Alan
Again, thank you, I did manage to spot that one (Miraculously) and correct it, the other issue was simply you were only working with the first 10 rows whereas the log has over 5000
Doh!

All working now, I struggle to grasp the -- element of these formulas, being a rank amateur, it's a huge help having guys like yourself willing to help. Much appreciated.
 
Upvote 0
Alan
Again, thank you, I did manage to spot that one (Miraculously) and correct it, the other issue was simply you were only working with the first 10 rows whereas the log has over 5000
Doh!

All working now, I struggle to grasp the -- element of these formulas, being a rank amateur, it's a huge help having guys like yourself willing to help. Much appreciated.

the --(..etc) is to convert the array of (true,true, false,.....etc) to (1,1,0,...) so that the sumproduct() can multiply them with the other arrays
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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