CountIfs spanning two date range across Midnight

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
946
Office Version
  1. 2016
Platform
  1. Windows
Hello All
I'm trying to count the number of entries that the Time in column U falls within the time ranges in Q2 & R2, based upon the dates in column AA.
Because the time frame (Q2 & R2) cross midnight into the next day. I am attempting to add the the next date in AA.
For example, If 2nd shift begins on 1-3-2022 (AA3) and ends the next day on 1-4-2022 (AA4) at 4:00am, then those two dates need to be combined to form one segment of 2nd shift.
Kind of hard to explain
In AE3 I have the below formula to try and add the two dates together to form one segment
Rich (BB code):
=COUNTIFS($T:$T,$AA3,$U:$U,$U3>=$Q$2)&(COUNTIFS($T:$T,$AA4,$U:$U,$U3<=$R$2))

counting 1st shift I can do as it falls on the same date, with out crossing midnight to the next day.

thank you for your help

1643300213873.png
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I should suggest using
Excel Formula:
=SUMPRODUCT(--(($T$1:$T$1000+$U$1:$U$1000)>=(AA2+$Q$2)),--(($T$1:$T$00+$U$1:$U$1000)<=(AA2+1+$R$2)))

Bye
 
Upvote 0
Solution
Thanks for you help.
I used:
Rich (BB code):
=SUMPRODUCT(--(($T$1:$T$1000+$U$1:$U$1000)>=(AA3+$Q$2)),--(($T$1:$T$1000+$U$1:$U$1000)<=(AA3+1+$R$2)))

Result was a #VALUE error
 
Upvote 0
I changed it around a bit, and seems to be working:
Rich (BB code):
=SUMPRODUCT(--(($T$3:$T$1000+$U$3:$U$1000)>=($AA4+$Q$2)),--(($T$3:$T$1000+$U$3:$U$1000)<=($AA4+1+$R$2)))

Thank you
Not following how SUMPRODUCT is working for a COUNTIFS...that seems odd. but it is working.
 
Upvote 0
The error was caused by the strings in the headers, that I didn't insert in my test workbook.
You fixed it, good.

Bye
 
Upvote 0
($T$3:$T$1000+$U$3:$U$1000)>=($AA4+$Q$2) will return a list of True/False; the "--" forces those T/F to become 1/0 that SumProduct will work on.

Bye
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

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