Count of time slot

Sri_33

Board Regular
Joined
Sep 8, 2020
Messages
119
Office Version
  1. 2016
Platform
  1. Windows
Book1
ABCDE
1TimeStartEndCount
213:3013:0013:293
313:00
412:30
514:00
613:00
713:30
813:00
913:30
1014:00
1115:00
1214:30
1312:30
1414:00
1513:30
1615:00
1714:00
Sheet1


Hello all, I want the count of the time slots from column A which are in between(C2 & D2 Cells) to be projected in E2 cell, please help me with the formula.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try:

Book2
ABCDE
1TimeStartEndCount
21:30:00 PM1:00:00 PM1:29:00 PM3
31:00:00 PM
412:30:00 PM
52:00:00 PM
61:00:00 PM
71:30:00 PM
81:00:00 PM
91:30:00 PM
102:00:00 PM
113:00:00 PM
122:30:00 PM
1312:30:00 PM
142:00:00 PM
151:30:00 PM
163:00:00 PM
172:00:00 PM
Sheet13
Cell Formulas
RangeFormula
E2E2=COUNTIFS(A2:A20,">="&C2,A2:A20,"<="&D2)
 
Upvote 0
Try:

Book2
ABCDE
1TimeStartEndCount
21:30:00 PM1:00:00 PM1:29:00 PM3
31:00:00 PM
412:30:00 PM
52:00:00 PM
61:00:00 PM
71:30:00 PM
81:00:00 PM
91:30:00 PM
102:00:00 PM
113:00:00 PM
122:30:00 PM
1312:30:00 PM
142:00:00 PM
151:30:00 PM
163:00:00 PM
172:00:00 PM
Sheet13
Cell Formulas
RangeFormula
E2E2=COUNTIFS(A2:A20,">="&C2,A2:A20,"<="&D2)
it is working thank you
 
Upvote 0
Breaks TC.xlsx
ABCDEF
1MealM1-End
20:000:15
30:000:15
40:000:150:000:1547
50:000:15
60:000:15
70:000:15
80:000:15
90:000:15
100:000:15
110:000:15
120:000:15
130:000:15
140:000:15
150:000:15
160:000:15
170:000:15
180:000:15
190:000:15
200:000:15
210:000:15
220:000:15
230:000:15
240:000:15
250:000:15
260:000:15
270:000:15
280:000:15
290:000:15
300:000:15
310:000:15
320:000:15
330:000:15
340:000:15
350:000:15
360:000:15
370:000:15
380:000:15
390:000:15
400:000:15
410:000:15
420:000:15
430:000:15
440:000:15
450:000:15
460:000:15
470:000:15
480:000:15
490:000:15
500:000:15
510:000:15
520:000:15
530:000:15
540:000:15
550:000:15
560:000:15
570:000:15
580:000:15
590:000:15
600:000:15
610:000:15
620:000:15
630:000:15
640:000:15
650:000:15
660:000:15
670:000:15
680:000:15
690:000:15
700:000:15
710:000:15
720:000:15
730:000:15
740:000:15
750:000:15
760:000:15
770:000:15
780:000:15
790:000:15
800:000:15
810:000:15
820:000:15
830:000:15
840:000:15
850:000:15
860:000:15
870:000:15
880:000:15
890:000:15
900:000:15
910:000:15
920:000:15
930:000:15
940:000:15
950:000:15
960:000:15
970:000:15
980:000:15
990:000:15
1000:000:15
1010:000:15
1020:000:15
1030:000:15
1040:000:15
1050:000:15
1060:000:15
1070:000:15
1080:000:15
1090:000:15
1100:000:15
1110:000:15
1120:000:15
Sheet4
Cell Formulas
RangeFormula
F4F4=COUNTIFS(A:A,"="&D4,B:B,"="&E4)


the count should be coming as 111 in F4 cell, but it is showing as 47, please help me in this.
 
Upvote 0
You have the values in columns A:B formatted as times, so that's all you see. But if you change the format to General, and show more decimal places, this is what you see:

Book1
ABCDEF
1MealM1-End
20.000000000.010417
30.000000000.010417
41.000000001.01041700.0104166666666747
51.000000001.010417111
61.000000001.010417
71.000000001.010417
80.000000000.010417
90.000000000.010417
101.000000001.010417
111.000000001.010417
120.000000000.010417
131.000000001.010417
140.000000000.010417
150.000000000.010417
161.000000001.010417
171.000000001.010417
181.000000001.010417
191.000000001.010417
201.000000001.010417
211.000000001.010417
221.000000001.010417
231.000000001.010417
240.000000000.010417
251.000000001.010417
261.000000001.010417
271.000000001.010417
280.000000000.010417
291.000000001.010417
301.000000001.010417
311.000000001.010417
320.000000000.010417
331.000000001.010417
340.000000000.010417
350.000000000.010417
360.000000000.010417
370.000000000.010417
380.000000000.010417
391.000000001.010417
401.000000001.010417
410.000000000.010417
421.000000001.010417
431.000000001.010417
440.000000000.010417
451.000000001.010417
460.000000000.010417
471.000000001.010417
481.000000001.010417
491.000000001.010417
500.000000000.010417
511.000000001.010417
521.000000001.010417
530.000000000.010417
540.000000000.010417
551.000000001.010417
560.000000000.010417
571.000000001.010417
581.000000001.010417
590.000000000.010417
601.000000001.010417
611.000000001.010417
620.000000000.010417
631.000000001.010417
640.000000000.010417
650.000000000.010417
661.000000001.010417
671.000000001.010417
680.000000000.010417
691.000000001.010417
701.000000001.010417
710.000000000.010417
721.000000001.010417
731.000000001.010417
740.000000000.010417
750.000000000.010417
761.000000001.010417
771.000000001.010417
780.000000000.010417
791.000000001.010417
801.000000001.010417
811.000000001.010417
820.000000000.010417
831.000000001.010417
841.000000001.010417
850.000000000.010417
860.000000000.010417
871.000000001.010417
881.000000001.010417
891.000000001.010417
900.000000000.010417
910.000000000.010417
920.000000000.010417
931.000000001.010417
940.000000000.010417
950.000000000.010417
961.000000001.010417
971.000000001.010417
980.000000000.010417
991.000000001.010417
1001.000000001.010417
1010.000000000.010417
1021.000000001.010417
1030.000000000.010417
1040.000000000.010417
1050.000000000.010417
1061.000000001.010417
1071.000000001.010417
1081.000000001.010417
1091.000000001.010417
1100.000000000.010417
1110.000000000.010417
1120.000000000.010417
113
114
Sheet3
Cell Formulas
RangeFormula
F4F4=COUNTIFS(A:A,"="&D4,B:B,"="&E4)
F5F5=SUMPRODUCT(--(MOD(A2:A112,1)<=MOD(D4,1)),--(MOD(A2:A112,1)<=MOD(E4,1)))


A date is a number (the number of days since January 1, 1900), and a time is a fraction of a day. So looking at these times, some of them start with a 1, meaning the next day. These are the ones that are not counted. You don't see the 1 because of how the cell is formatted. To clear it up, you need to remove the leading 1s.

It's also worth noting that since times are fractions of a day, and fractions cannot be stored exactly in Excel, sometimes you get odd mismatches as well. You might want to change the E4 cell to 00:15:01.

If you do not care about the leading 1s, and you just want to compare the time portions, try the formula in F5.

Good luck!
 
Upvote 0
You have the values in columns A:B formatted as times, so that's all you see. But if you change the format to General, and show more decimal places, this is what you see:

Book1
ABCDEF
1MealM1-End
20.000000000.010417
30.000000000.010417
41.000000001.01041700.0104166666666747
51.000000001.010417111
61.000000001.010417
71.000000001.010417
80.000000000.010417
90.000000000.010417
101.000000001.010417
111.000000001.010417
120.000000000.010417
131.000000001.010417
140.000000000.010417
150.000000000.010417
161.000000001.010417
171.000000001.010417
181.000000001.010417
191.000000001.010417
201.000000001.010417
211.000000001.010417
221.000000001.010417
231.000000001.010417
240.000000000.010417
251.000000001.010417
261.000000001.010417
271.000000001.010417
280.000000000.010417
291.000000001.010417
301.000000001.010417
311.000000001.010417
320.000000000.010417
331.000000001.010417
340.000000000.010417
350.000000000.010417
360.000000000.010417
370.000000000.010417
380.000000000.010417
391.000000001.010417
401.000000001.010417
410.000000000.010417
421.000000001.010417
431.000000001.010417
440.000000000.010417
451.000000001.010417
460.000000000.010417
471.000000001.010417
481.000000001.010417
491.000000001.010417
500.000000000.010417
511.000000001.010417
521.000000001.010417
530.000000000.010417
540.000000000.010417
551.000000001.010417
560.000000000.010417
571.000000001.010417
581.000000001.010417
590.000000000.010417
601.000000001.010417
611.000000001.010417
620.000000000.010417
631.000000001.010417
640.000000000.010417
650.000000000.010417
661.000000001.010417
671.000000001.010417
680.000000000.010417
691.000000001.010417
701.000000001.010417
710.000000000.010417
721.000000001.010417
731.000000001.010417
740.000000000.010417
750.000000000.010417
761.000000001.010417
771.000000001.010417
780.000000000.010417
791.000000001.010417
801.000000001.010417
811.000000001.010417
820.000000000.010417
831.000000001.010417
841.000000001.010417
850.000000000.010417
860.000000000.010417
871.000000001.010417
881.000000001.010417
891.000000001.010417
900.000000000.010417
910.000000000.010417
920.000000000.010417
931.000000001.010417
940.000000000.010417
950.000000000.010417
961.000000001.010417
971.000000001.010417
980.000000000.010417
991.000000001.010417
1001.000000001.010417
1010.000000000.010417
1021.000000001.010417
1030.000000000.010417
1040.000000000.010417
1050.000000000.010417
1061.000000001.010417
1071.000000001.010417
1081.000000001.010417
1091.000000001.010417
1100.000000000.010417
1110.000000000.010417
1120.000000000.010417
113
114
Sheet3
Cell Formulas
RangeFormula
F4F4=COUNTIFS(A:A,"="&D4,B:B,"="&E4)
F5F5=SUMPRODUCT(--(MOD(A2:A112,1)<=MOD(D4,1)),--(MOD(A2:A112,1)<=MOD(E4,1)))


A date is a number (the number of days since January 1, 1900), and a time is a fraction of a day. So looking at these times, some of them start with a 1, meaning the next day. These are the ones that are not counted. You don't see the 1 because of how the cell is formatted. To clear it up, you need to remove the leading 1s.

It's also worth noting that since times are fractions of a day, and fractions cannot be stored exactly in Excel, sometimes you get odd mismatches as well. You might want to change the E4 cell to 00:15:01.

If you do not care about the leading 1s, and you just want to compare the time portions, try the formula in F5.

Good luck!
Hello Eric, I have few doubts here,
1) Which format the above mentioned cells(A & B columns) are in, because when Iam trying in the date formated cells formula mentioned in F5 cell is not giving the correct output.
2) I want to apply other conditions as well( location, shift etc mentioned in the screenshot for reference) can I add these conditions in Sumproduct function?
3) Is there any other way to only get the time values?

1636072315979.png
 
Upvote 0
1) Based on your example, the timestamps in column B have a 1 or a 0 on it based on if column A has a 1 or a 0. If so, we can just subtract column A from column B to get a time. It looks like columns A:B are being populated by some other software, so we need to understand what it's giving us. As far as formatting column B, I'd recommend using the usual time format (which I did on the lower half of my table below).

2) Yes, we can easily add other conditions, see below.

3) I'm getting the time values only by subtracting column A. It seems to work, but on your whole data set, make sure that subtracting column A is right. But are you sure you want the timestamps? Do you want to include column A as a condition, in other words, you want to make sure column A is a 1 before you count it?

Book2
ABCDEFGHIJ
1MealM1-EndShiftLocationStartEndShiftLocationCount
200.01041667MorningBS0:000:15MorningTP4
300.01041667MorningTP
411.01041667MorningTP
511.01041667MorningTP
611.01041667MorningTP
711.01041667MorningBS
800.01041667MorningBS
900.01041667MidKL
1010:15MidKL
1110:15MidKL
1200:15MidKL
1310:15MidKL
1400:15MorningBS
1500:15MorningBS
1610:15NightBS
17
Sheet13
Cell Formulas
RangeFormula
J2J2=SUMPRODUCT(--(B2:B16-A2:A16>=F2),--(B2:B16-A2:A16<=G2),--(C2:C16=H2),--(D2:D16=I2))
 
Upvote 0
Solution

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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