Countifs function for Date & Time Range not counting all cells

SMcCafferty

New Member
Joined
May 5, 2022
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
I am using the formula below to count all cells that fall between two specified date/time ranges. From what I can tell, it is counting the cells between the two date/times but not the boundary cells which meet the criteria.

The function is counting cells on a separate worksheet, but is contained within the same workbook. The References AL2 and AL3 are helper cells I created to combine the Date and Time entered on the sheet specifying the date/time range needed.

=COUNTIFS('KPI Table'!AM3:AM491,">"&AL2,'KPI Table'!AM3:AM491,"<"&AL3)

I am also using SUMIFS formulas in the adjacent cells and getting the same result.

Any help would be greatly appreciated.

PS: Below is the code from the two sheets I am using captured by Xl2BB. Not sure if that is what you want. I dont see an option where I can upload the actual Excel file.

Countifs Example.xlsx
ABCD
8Total Frac Stages4
9Total Pumping Hours10:56
10Total NPT Hours5:42
Daily Ops Report
Cell Formulas
RangeFormula
C8C8=COUNTIFS('KPI Table'!AM3:AM491,">"&AL2,'KPI Table'!AM3:AM491,"<"&AL3)
C9C9=SUMIFS('KPI Table'!AN3:AN491,'KPI Table'!AM3:AM491,"<="&AL3,'KPI Table'!AM3:AM491,">="&AL2)
C10C10=SUMIFS('KPI Table'!AO3:AO491,'KPI Table'!AM3:AM491,">="&AL2,'KPI Table'!AM3:AM491,"<="&AL3)


Cell Formulas
RangeFormula
AK3:AK13AK3=IF('C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!A6="","",'C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!A6)
AL3:AL13AL3=IF('C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!L6="","",'C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!L6)
AM3:AM13AM3=AK3+AL3
AN3:AN13AN3=IF('C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!M6="","",'C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!M6)
AO3:AO13AO3=IFERROR('C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!J6+'C:\Users\spmcc\Documents\4. Job Management Packet\[JMP 6.06 Vlookup.xlsm]Frac Stage Tracker'!P6,"")
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Your 2nd XL2BB is full of exgternal references to errors out at my end.
I am not entirely clear on what you are trying to do.
I am also struggling with this statement and then using < & > in the formula and not =< & >=.
From what I can tell, it is counting the cells between the two date/times but not the boundary cells which meet the criteria.
So a bit of a shot in the dark, does this work.
Excel Formula:
=COUNTIFS('KPI Table'!AM3:AM491,">"&ROUND(AL2-0.00001,5),'KPI Table'!AM3:AM491,"<"&ROUND(AL2+0.00001,5))
 
Upvote 0
Your 2nd XL2BB is full of exgternal references to errors out at my end.
I am not entirely clear on what you are trying to do.
I am also struggling with this statement and then using < & > in the formula and not =< & >=.

So a bit of a shot in the dark, does this work.
Excel Formula:
=COUNTIFS('KPI Table'!AM3:AM491,">"&ROUND(AL2-0.00001,5),'KPI Table'!AM3:AM491,"<"&ROUND(AL2+0.00001,5))

First and foremost, I apologize for the mess I sent the first time. It was my first time using XL2BB and it appears I made a pig's ear of it. The short answer to your formula is that no, it did not work. But, I realize I may not have been clear enough in my first attempt at explaining so please allow me to clarify;
1. The original formula was "<=" and also ">=" I accidentally sent my last attempt at trying some permutations to resolve the issue.
2. I hope the examples below will help better. But essentially, I am trying to count cells that are within a 24Hr period. The first mini-sheet is taken from the report where I am displaying the data. For the purposes of this I moved the helper column which combines the date and time entries into one cell to cells E2 and E3. This will take the place of AL2 and AL3. The location of the cells I am not concerned with, I can adjust the formula once I know what I am doing wrong.
3. The cells that I am trying to count are in a table contained on a separate worksheet (KPI Table), but, both worksheets are in the same workbook. That is the second mini-sheet in this reply.

Thank you for replying so quickly and helping me on this.

JMP 6.06 Vlookup.xlsm
ABCDE
1From:4/7/20226:00 AM4/7/22 6:00
2To:4/8/20226:00 AM4/8/22 6:00
3
4Pad Name/Well NumbersPLU 18 TWR : 152H 162H
5
6Operations Stats
7Total Frac Stages0
8Total Pumping Hours10:56
9Total NPT Hours5:42
Daily Ops Report
Cell Formulas
RangeFormula
E1:E2E1=B1+C1
D4D4=CONCATENATE('Well Data Input'!C1&": "&'Well Data Input'!B12&" "&'Well Data Input'!D12&" "&'Well Data Input'!F12&" "&'Well Data Input'!H12&" "&'Well Data Input'!J12&" "&'Well Data Input'!L12&" "&'Well Data Input'!N12&" "&'Well Data Input'!P12)
C7C7=COUNTIFS('KPI Table'!B2:B491,">="&ROUND(E2-0.00001,5),'KPI Table'!B2:B491,"<="&ROUND(E3+0.00001,5))
C8C8=SUMIFS('KPI Table'!$G$2:$G$491,'KPI Table'!$B$2:$B$491,"<="&$AL$3,'KPI Table'!$B$2:$B$491,">="&$AL$2)
C9C9=SUMIFS('KPI Table'!$AF$2:$AF$491,'KPI Table'!$B$2:$B$491,"<="&$AL$3,'KPI Table'!$B$2:$B$491,">="&$AL$2)
Named Ranges
NameRefers ToCells
'KPI Table'!_FilterDatabase='KPI Table'!$B$2:$B$491C7:C9
'KPI Table'!Criteria='KPI Table'!$B$2:$B$491C7:C9
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B1:B2Cellcontains a blank value textNO


Cell Formulas
RangeFormula
B2:B34B2=IF('Frac Stage Tracker'!$A6+'Frac Stage Tracker'!$L6="","",'Frac Stage Tracker'!$A6+'Frac Stage Tracker'!$L6)
C2:C34C2=IF('Frac Stage Tracker'!B6="","",'Frac Stage Tracker'!B6)
D2:D34D2=IF('Frac Stage Tracker'!D6="","",'Frac Stage Tracker'!D6)
E2:E34E2=IF('Frac Stage Tracker'!G6="","",'Frac Stage Tracker'!G6)
F2:F34F2=IF('Frac Stage Tracker'!J6=0,"",'Frac Stage Tracker'!J6)
G2:G34G2=IF('Frac Stage Tracker'!M6=0,"",'Frac Stage Tracker'!M6)
H2:H34H2=IF('Frac Stage Tracker'!P6=0,"",'Frac Stage Tracker'!P6)
 
Upvote 0
Can you copy KPI Table as values only to another sheet and then post an XL2BB of that here.
(I don't have Frac Stage Tracker so I finish up with no data in KPI Table)
Also your sample results rely on AL2 & AL3, but it is not showing in your Daily Ops report. What values do you have in AL2 & 3 that are used be C7-C9.

If you need to you can share the workbook via Google Drive, One Drive, Dropbox etc. Just allow anyone with the link to access it and post the link here.
 
Upvote 0
Can you copy KPI Table as values only to another sheet and then post an XL2BB of that here.
(I don't have Frac Stage Tracker so I finish up with no data in KPI Table)
Also your sample results rely on AL2 & AL3, but it is not showing in your Daily Ops report. What values do you have in AL2 & 3 that are used be C7-C9.

If you need to you can share the workbook via Google Drive, One Drive, Dropbox etc. Just allow anyone with the link to access it and post the link here.

Alex,
For the purposes of this I moved AL2 and AL3 to cells E2 and E3 in the first mini sheet on the last post. I figured it would be easier. The actual report is quite large and as I don't want AL2 and AL3 visible to the user it exists outside of the printable area in hidden cells. Below is a sample from the KPI table in values only. I apologize for all of this. The workbook is quite large and loaded with VBA, Macros and formulas.

KPI Table-Values Only.xlsx
ABCDEFG
1DateWell NameStageTransition Time (Hrs)NPT (Hrs)Pump Time (Hrs)Add. NPT (Hrs)
24/7/22 0:15152H10:162:09
34/7/22 5:53162H10:302:302:38
44/7/22 8:25152H20:303:052:12
54/7/22 13:33162H20:301:083:30
64/7/22 16:21152H30:300:132:05
74/7/22 22:21162H30:301:163:09
84/7/22 2:28152H40:301:262:20
94/7/22 5:54162H40:300:392:17
104/8/22 9:15152H50:300:152:36
114/8/22 15:40162H50:303:152:40
124/9/22 6:35152H60:3012:062:19
134/9/22 10:09162H60:300:392:25
144/9/22 13:29152H70:300:312:19
154/9/22 17:03162H70:300:172:47
164/9/22 22:08152H80:300:303:190:46
174/9/22 1:19162H80:305:052:41
184/9/22 4:47152H90:300:272:31
194/10/22 8:00162H90:382:35
204/10/22 14:32152H100:303:492:13
214/10/22 17:07162H100:082:27
224/10/22 21:11152H110:300:372:57
234/11/22 0:43162H110:300:422:20
244/11/22 4:59152H120:301:382:08
254/11/22 8:08162H120:300:082:31
264/11/22 10:41152H130:232:10
274/11/22 14:13162H130:300:052:57
284/11/22 16:45152H140:212:11
294/11/22 19:31162H140:282:18
304/11/22 1:27152H150:303:032:23
314/11/22 6:13162H150:301:163:00
324/12/22 9:58152H160:300:382:37
334/12/22 13:41162H160:300:332:40
344/12/22 16:23152H170:300:072:05
354/12/22 19:23162H170:292:31
Sheet1
 
Upvote 0
Your pumping SUMIFS formula seems to be working fine. Can you give me an example of it not working.
eg the AL values for
Start Date & Time
End Date & Time
Pumping Value expected result
actual result
 
Upvote 0
Your pumping SUMIFS formula seems to be working fine. Can you give me an example of it not working.
eg the AL values for
Start Date & Time
End Date & Time
Pumping Value expected result
actual result
Alex,

On the CountIf (Total Stages) the Ops Report shows a result of 4. But the value should be 6 as there were 6 stages completed between 4/7 6AM and 4/8 6AM. The pumping and NPT hours are also only counting 4 stages worth of time.
 

Attachments

  • Actual Stages.png
    Actual Stages.png
    11.6 KB · Views: 7
  • Ops Report Results = 4.png
    Ops Report Results = 4.png
    19.7 KB · Views: 6
Upvote 0
On the CountIf (Total Stages) the Ops Report shows a result of 4. But the value should be 6 as there were 6 stages completed between 4/7 6AM and 4/8 6AM. The pumping and NPT hours are also only counting 4 stages worth of time.
Unless I am issing something the result of 4 is correct.
Your start date & time it FROM 6 AM on 4 Jul 2022.

2 of the times you are counting in your check total of 6 are before 6 AM.


1651912313341.png
 
Upvote 0
Unless I am issing something the result of 4 is correct.
Your start date & time it FROM 6 AM on 4 Jul 2022.

2 of the times you are counting in your check total of 6 are before 6 AM.


View attachment 64071
Yes sir, I need to count those. The time span is from 6am to 6am. So, I need it to count all cells that begin after 6AM on 4/7 and before 6AM on 4/8/
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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