countifs if criteria is not alligned with criteria range

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
350
Office Version
  1. 365
Platform
  1. Windows
how to count a criteria if its not alligned with criteria range. Please see below table. need to count the hours between 2 dates (from/to). however, dates are not alligned with the hours.

Book2
ABCDEFGHIJKLMNO
1EXPECTED RESULT
2FROMTO
3Name11-08-2314-08-2311-08-2312-08-2313-08-2314-08-23
4Count of 12 hrsCount of 8hrsDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURS
5name104ABCshift 18ABCshift 18ABCshift 18ABCshift 18
6name204DEFshift 28DEFshift 28DEFshift 28DEFshift 28
7name340ABCshift 312ABCshift 312ABCshift 312ABCshift 312
8name400DEFshift 10DEFshift 10DEFshift 10DEFshift 10
9name504ABCshift 28ABCshift 28ABCshift 28ABCshift 28
10name640DEFshift 312DEFshift 312DEFshift 312DEFshift 312
11name704ABCshift 18ABCshift 18ABCshift 18ABCshift 18
12name804DEFshift 28DEFshift 28DEFshift 28DEFshift 28
13name904ABCshift 38ABCshift 38ABCshift 38ABCshift 38
14name1040DEFshift 112DEFshift 112DEFshift 112DEFshift 112
15name1140ABCshift 212ABCshift 212ABCshift 212ABCshift 212
16name1204DEFshift 38DEFshift 38DEFshift 38DEFshift 38
17name1300EFGOFF0EFGOFF0EFGOFF0EFGOFF0
Sheet1
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Good to hear you figured it out.
If you would like to post the actual solution then it is perfectly fine to mark that post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0
BTW, as I understand it you can achieve what you want without the volatile function OFFSET
You may have to adjust the ranges to suit your actual data, but this non-volatile formula produces the expected results for that sample data.

23 08 14.xlsm
BCDEFGHIJKLMNO
1EXPECTED RESULT
2FROMTO
311/08/2314/08/2311/08/2312/08/2313/08/2314/08/23
4Count of 12 hrsCount of 8hrsDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURS
504ABCshift 18ABCshift 18ABCshift 18ABCshift 18
604DEFshift 28DEFshift 28DEFshift 28DEFshift 28
740ABCshift 312ABCshift 312ABCshift 312ABCshift 312
800DEFshift 10DEFshift 10DEFshift 10DEFshift 10
904ABCshift 28ABCshift 28ABCshift 28ABCshift 28
1040DEFshift 312DEFshift 312DEFshift 312DEFshift 312
1104ABCshift 18ABCshift 18ABCshift 18ABCshift 18
1204DEFshift 28DEFshift 28DEFshift 28DEFshift 28
1304ABCshift 38ABCshift 38ABCshift 38ABCshift 38
1440DEFshift 112DEFshift 112DEFshift 112DEFshift 112
1540ABCshift 212ABCshift 212ABCshift 212ABCshift 212
1604DEFshift 38DEFshift 38DEFshift 38DEFshift 38
1700EFGOFF0EFGOFF0EFGOFF0EFGOFF0
Count hours
Cell Formulas
RangeFormula
B5:B17B5=COUNT(FILTER(F5:O5,(D$3:M$3>=B$3)*(D$3:M$3<=C$3)*(F$4:O$4="HOURS")*(F5:O5=12),""))
C5:C17C5=COUNT(FILTER(F5:O5,(D$3:M$3>=B$3)*(D$3:M$3<=C$3)*(F$4:O$4="HOURS")*(F5:O5=8),""))
 
Upvote 1
i figure it out using offset function.. thanks
posting my solution using countifs with offset function.


Book2
ABCDEFGHIJKLMNO
1EXPECTED RESULT
2FROMTO
3Name11-08-2314-08-2311-08-2312-08-2313-08-2314-08-23
4Count of 12 hrsCount of 8hrsDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURS
5name104ABCshift 18ABCshift 18ABCshift 18ABCshift 18
6name204DEFshift 28DEFshift 28DEFshift 28DEFshift 28
7name340ABCshift 312ABCshift 312ABCshift 312ABCshift 312
8name400DEFshift 10DEFshift 10DEFshift 10DEFshift 10
9name504ABCshift 28ABCshift 28ABCshift 28ABCshift 28
10name640DEFshift 312DEFshift 312DEFshift 312DEFshift 312
11name704ABCshift 18ABCshift 18ABCshift 18ABCshift 18
12name804DEFshift 28DEFshift 28DEFshift 28DEFshift 28
13name904ABCshift 38ABCshift 38ABCshift 38ABCshift 38
14name1040DEFshift 112DEFshift 112DEFshift 112DEFshift 112
15name1140ABCshift 212ABCshift 212ABCshift 212ABCshift 212
16name1204DEFshift 38DEFshift 38DEFshift 38DEFshift 38
17name1312EFGOFF12EFGOFF8EFGOFF8EFGOFF0
Sheet1
Cell Formulas
RangeFormula
B5:B17B5=COUNTIFS($D5:$O5,12,OFFSET($D$3:$O$3,0,-2),">="&$B$3,OFFSET($D$3:$O$3,0,-2),"<="&$C$3)
C5:C17C5=COUNTIFS($D5:$O5,8,OFFSET($D$3:$O$3,0,-2),">="&$B$3,OFFSET($D$3:$O$3,0,-2),"<="&$C$3)
 
Upvote 0
Solution
posting my solution using countifs with offset function.
:confused: I don't know why you would use the volatile OFFSET function when it is not needed.
Did you try the non-volatile alternative?

It seems from your solution that Department and Shift cannot contain numbers so the non-volatile alternative can also be reduced as follows. It is both shorter and more efficient than using OFFSET

23 08 14.xlsm
BCDEFGHIJKLMNO
1EXPECTED RESULT
2FROMTO
311/08/2314/08/2311/08/2312/08/2313/08/2314/08/23
4Count of 12 hrsCount of 8hrsDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURS
504ABCshift 18ABCshift 18ABCshift 18ABCshift 18
604DEFshift 28DEFshift 28DEFshift 28DEFshift 28
740ABCshift 312ABCshift 312ABCshift 312ABCshift 312
800DEFshift 10DEFshift 10DEFshift 10DEFshift 10
904ABCshift 28ABCshift 28ABCshift 28ABCshift 28
1040DEFshift 312DEFshift 312DEFshift 312DEFshift 312
1104ABCshift 18ABCshift 18ABCshift 18ABCshift 18
1204DEFshift 28DEFshift 28DEFshift 28DEFshift 28
1304ABCshift 38ABCshift 38ABCshift 38ABCshift 38
1440DEFshift 112DEFshift 112DEFshift 112DEFshift 112
1540ABCshift 212ABCshift 212ABCshift 212ABCshift 212
1604DEFshift 38DEFshift 38DEFshift 38DEFshift 38
1712EFGOFF12EFGOFF8EFGOFF8EFGOFF0
Count hours
Cell Formulas
RangeFormula
B5:B17B5=COUNT(FILTER(F5:O5,(D$3:M$3>=B$3)*(D$3:M$3<=C$3)*(F5:O5=12),""))
C5:C17C5=COUNT(FILTER(F5:O5,(D$3:M$3>=B$3)*(D$3:M$3<=C$3)*(F5:O5=8),""))
 
Upvote 0
:confused: I don't know why you would use the volatile OFFSET function when it is not needed.
Did you try the non-volatile alternative?

It seems from your solution that Department and Shift cannot contain numbers so the non-volatile alternative can also be reduced as follows. It is both shorter and more efficient than using OFFSET

23 08 14.xlsm
BCDEFGHIJKLMNO
1EXPECTED RESULT
2FROMTO
311/08/2314/08/2311/08/2312/08/2313/08/2314/08/23
4Count of 12 hrsCount of 8hrsDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURS
504ABCshift 18ABCshift 18ABCshift 18ABCshift 18
604DEFshift 28DEFshift 28DEFshift 28DEFshift 28
740ABCshift 312ABCshift 312ABCshift 312ABCshift 312
800DEFshift 10DEFshift 10DEFshift 10DEFshift 10
904ABCshift 28ABCshift 28ABCshift 28ABCshift 28
1040DEFshift 312DEFshift 312DEFshift 312DEFshift 312
1104ABCshift 18ABCshift 18ABCshift 18ABCshift 18
1204DEFshift 28DEFshift 28DEFshift 28DEFshift 28
1304ABCshift 38ABCshift 38ABCshift 38ABCshift 38
1440DEFshift 112DEFshift 112DEFshift 112DEFshift 112
1540ABCshift 212ABCshift 212ABCshift 212ABCshift 212
1604DEFshift 38DEFshift 38DEFshift 38DEFshift 38
1712EFGOFF12EFGOFF8EFGOFF8EFGOFF0
Count hours
Cell Formulas
RangeFormula
B5:B17B5=COUNT(FILTER(F5:O5,(D$3:M$3>=B$3)*(D$3:M$3<=C$3)*(F5:O5=12),""))
C5:C17C5=COUNT(FILTER(F5:O5,(D$3:M$3>=B$3)*(D$3:M$3<=C$3)*(F5:O5=8),""))
Sir, I am aware that offset function its volatile. Actually, your formula was considered. However, when i transfer your formula to the user, i found out that his excel version is lower than 365.
 
Upvote 0
However, when i transfer your formula to the user, i found out that his excel version is lower than 365.
Good idea to put that information in your first post if possible as helpers naturally otherwise assume the version(s) shown in your profile. ;)

For lower versions at least as far back as 2010 you could try this non-volatile version.

23 08 20.xlsm
BCDEFGHIJKLMNO
2FROMTO
311/08/2314/08/2311/08/2312/08/2313/08/2314/08/23
4Count of 12 hrsCount of 8hrsDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURSDepartmentShiftHOURS
504ABCshift 18ABCshift 18ABCshift 18ABCshift 18
604DEFshift 28DEFshift 28DEFshift 28DEFshift 28
740ABCshift 312ABCshift 312ABCshift 312ABCshift 312
800DEFshift 10DEFshift 10DEFshift 10DEFshift 10
904ABCshift 28ABCshift 28ABCshift 28ABCshift 28
1040DEFshift 312DEFshift 312DEFshift 312DEFshift 312
1104ABCshift 18ABCshift 18ABCshift 18ABCshift 18
1204DEFshift 28DEFshift 28DEFshift 28DEFshift 28
1304ABCshift 38ABCshift 38ABCshift 38ABCshift 38
1440DEFshift 112DEFshift 112DEFshift 112DEFshift 112
1540ABCshift 212ABCshift 212ABCshift 212ABCshift 212
1604DEFshift 38DEFshift 38DEFshift 38DEFshift 38
1712EFGOFF12EFGOFF8EFGOFF8EFGOFF0
Sheet2 (3)
Cell Formulas
RangeFormula
B5:B17B5=COUNTIFS(F5:O5,12,D$3:M$3,">="&B$3,D$3:M$3,"<="&C$3)
C5:C17C5=COUNTIFS(F5:O5,8,D$3:M$3,">="&B$3,D$3:M$3,"<="&C$3)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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