COUNTIF Problems

LambChoptheKid

New Member
Joined
Dec 10, 2022
Messages
35
Office Version
  1. 365
Platform
  1. Windows
I'm having a problem with a COUNTIFS function that I've been working with. The logic of it seems sound to me but once the date moves to 10/2/2022 things seem to break.

The idea is to see if a machine is running based on the information in the table to the right.

Can someone help me understand what might be going on?

This is the formula that is used: =IF((COUNTIFS($E:$E,$A2,$F:$F,"<=" &$B2, $G:$G, ">=" &$B2))>0, "Yes", "No")

Thank you
 

Attachments

  • Forum Help2.PNG
    Forum Help2.PNG
    99.9 KB · Views: 41

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
PS. The reason that entire columns are utilized is because the table will be continuously updated
 
Upvote 0
For me it's returning Yes

Can you post you data using below link?

Book10
ABCDEFGH
1DateTimeRunningDate/TimeStartEnd
210/1/20221:00Yes10/1/20221:008:00
310/2/20222:00Yes10/1/202210:0012:00
410/2/20223:00Yes10/1/202212:0013:00
510/2/20225:00Yes10/1/202214:0015:00
610/2/20226:00Yes10/1/202215:0016:00
710/2/20227:00Yes10/2/20222:003:00
810/2/20228:00Yes10/2/20225:008:00
9
10
11
12
13
14
Sheet2
Cell Formulas
RangeFormula
C2:C8C2=IF(COUNTIFS(E:E,$A2,F:F,"<="&B2,G:G,">="&B2)>0,"Yes","No")
 
Upvote 0
COUNTIF Test.xlsx
ABCDEFG
1Date2TimeRUNNING?
210/1/20221:00YesDate/TimeStartEnd
310/1/20222:00Yes10/01/221:008:00
410/1/20223:00Yes10/1/202210:0012:00
510/1/20224:00Yes10/1/202212:0013:00
610/1/20225:00Yes10/1/202214:0015:00
710/1/20226:00Yes10/1/202215:0016:00
810/1/20227:00Yes10/2/20222:003:00
910/1/20228:00Yes10/2/20225:008:00
1010/1/20229:00No
1110/1/202210:00Yes
1210/1/202211:00Yes
1310/1/202212:00Yes
1410/1/202213:00Yes
1510/1/202214:00Yes
1610/1/202215:00Yes
1710/1/202216:00Yes
1810/1/202217:00No
1910/1/202218:00No
2010/1/202219:00No
2110/1/202220:00No
2210/1/202221:00No
2310/1/202222:00No
2410/1/202223:00No
2510/1/20220:00No
2610/2/20221:00No
2710/2/20222:00NoShould be "Yes"
2810/2/20223:00NoShould be "Yes"
2910/2/20224:00No
3010/2/20225:00NoShould be "Yes"
3110/2/20226:00NoShould be "Yes"
3210/2/20227:00NoShould be "Yes"
3310/2/20228:00NoShould be "Yes"
3410/2/20229:00No
3510/2/202210:00No
3610/2/202211:00No
3710/2/202212:00No
3810/2/202213:00No
3910/2/202214:00No
4010/2/202215:00No
4110/2/202216:00No
4210/2/202217:00No
4310/2/202218:00No
4410/2/202219:00No
4510/2/202220:00No
4610/2/202221:00No
4710/2/202222:00No
4810/2/202223:00No
4910/2/20220:00No
Sheet1
Cell Formulas
RangeFormula
C2:C49C2=IF((COUNTIFS($E:$E,$A2,$F:$F,"<=" &$B2, $G:$G, ">=" &$B2))>0, "Yes", "No")
 
Upvote 0
I looked at the data in your post, and it looks like you may not understand how Excel handles Time. As you know, a DATE is stored as a whole number between 1 and a 15 digit whole number where 1 represents 1/1/1900, and today (12/17/2022) = 44912.
Similarly, Excel uses DECIMAL numbers to represent Hours, Minutes, Seconds, Fractions of a second where 0 is Midnight (12:00:00 AM) and the 24 hours of a day are broken up increments of 1/(24*60*60) or 1/86400 or roughly 0.000012 per minute. This actually works well as Noon or 12 hours is 0.5 or half of 24 hours. Other times work out nicely as well.
As such, when a Time value is greater than or equal to 1 simply doesn't count the 1 because it's part of a Date value (1/1/1900).
The Time values in your table at row 24 to the bottom are all equal to or greater than 1. In order to do an accurate determination of the end value based on hours, you'd need to use a Date and Time values and formats (mm/dd/yyyy hh:mm AM/PM) for both the start and end values rather than just a date and number of hours.
If you wanted to use number of hours, your Date2 value should really be a date and time, and then if you use whole numbers for hours (ASSUMING you do NOT need more than 24 hours!), the end time would be Date2+(Time/86400) where Date2 is a Date and Time value like 44835.333333 for 10/01/2022 08:00 AM.

This table demonstrates that:
Book1
LMNOPQR
1Date/TimeStartHoursHours ValueStart DTEnd DTHours2
210/01/202201:00:00 AM08:000.33333310/01/2022 01:00 AM10/01/2022 09:00 AM08:00
310/01/202210:00:00 AM12:000.50000010/01/2022 10:00 AM10/01/2022 10:00 PM12:00
410/01/202212:00:00 PM13:000.54166710/01/2022 12:00 PM10/02/2022 01:00 AM13:00
510/01/202202:00:00 PM15:000.62500010/01/2022 02:00 PM10/02/2022 05:00 AM15:00
610/01/202203:00:00 PM16:000.66666710/01/2022 03:00 PM10/02/2022 07:00 AM16:00
710/02/202202:00:00 AM03:000.12500010/02/2022 02:00 AM10/02/2022 05:00 AM03:00
810/02/202205:00:00 PM08:000.33333310/02/2022 05:00 PM10/03/2022 01:00 AM08:00
Sheet1
Cell Formulas
RangeFormula
O2:O8O2=[@Hours]
P2:P8P2=L2+M2
Q2:Q8Q2=[@[Start DT]]+[@Hours]
R2:R8R2=[@[End DT]]-[@[Start DT]]

One other thing. Changing a value's alignment (right/center/left in particular) masks whether a cell's value is numeric (right aligned), text (left aligned) or a special value like TRUE or #N/A which are centered. It can also help in understanding what appear to be math errors, like when you KNOW a sum is wrong, and it ends up it's because it's SUMming decimal values displayed as whole numbers - or time values over 1!
Good luck.
 
Upvote 0
Solution
I looked at the data in your post, and it looks like you may not understand how Excel handles Time. As you know, a DATE is stored as a whole number between 1 and a 15 digit whole number where 1 represents 1/1/1900, and today (12/17/2022) = 44912.
Similarly, Excel uses DECIMAL numbers to represent Hours, Minutes, Seconds, Fractions of a second where 0 is Midnight (12:00:00 AM) and the 24 hours of a day are broken up increments of 1/(24*60*60) or 1/86400 or roughly 0.000012 per minute. This actually works well as Noon or 12 hours is 0.5 or half of 24 hours. Other times work out nicely as well.
As such, when a Time value is greater than or equal to 1 simply doesn't count the 1 because it's part of a Date value (1/1/1900).
The Time values in your table at row 24 to the bottom are all equal to or greater than 1. In order to do an accurate determination of the end value based on hours, you'd need to use a Date and Time values and formats (mm/dd/yyyy hh:mm AM/PM) for both the start and end values rather than just a date and number of hours.
If you wanted to use number of hours, your Date2 value should really be a date and time, and then if you use whole numbers for hours (ASSUMING you do NOT need more than 24 hours!), the end time would be Date2+(Time/86400) where Date2 is a Date and Time value like 44835.333333 for 10/01/2022 08:00 AM.

This table demonstrates that:
Book1
LMNOPQR
1Date/TimeStartHoursHours ValueStart DTEnd DTHours2
210/01/202201:00:00 AM08:000.33333310/01/2022 01:00 AM10/01/2022 09:00 AM08:00
310/01/202210:00:00 AM12:000.50000010/01/2022 10:00 AM10/01/2022 10:00 PM12:00
410/01/202212:00:00 PM13:000.54166710/01/2022 12:00 PM10/02/2022 01:00 AM13:00
510/01/202202:00:00 PM15:000.62500010/01/2022 02:00 PM10/02/2022 05:00 AM15:00
610/01/202203:00:00 PM16:000.66666710/01/2022 03:00 PM10/02/2022 07:00 AM16:00
710/02/202202:00:00 AM03:000.12500010/02/2022 02:00 AM10/02/2022 05:00 AM03:00
810/02/202205:00:00 PM08:000.33333310/02/2022 05:00 PM10/03/2022 01:00 AM08:00
Sheet1
Cell Formulas
RangeFormula
O2:O8O2=[@Hours]
P2:P8P2=L2+M2
Q2:Q8Q2=[@[Start DT]]+[@Hours]
R2:R8R2=[@[End DT]]-[@[Start DT]]

One other thing. Changing a value's alignment (right/center/left in particular) masks whether a cell's value is numeric (right aligned), text (left aligned) or a special value like TRUE or #N/A which are centered. It can also help in understanding what appear to be math errors, like when you KNOW a sum is wrong, and it ends up it's because it's SUMming decimal values displayed as whole numbers - or time values over 1!
Good luck.
You are correct, I did not understand that about how excel stores time. Thank you for taking the time to explain this. I'll take some time to learn about this and reconfigure my sheet.

Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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