Count the number of cells until a value is reached w/multiple criteria

Degausser124

New Member
Joined
Jun 14, 2022
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
Hi!

First, big thanks to everyone who helps on this forum. I reference this board at least weekly and I'd be lost without you all.

Attached is a dumbed down version of my file. What I'm looking to do is:
  • Count the number of cells in the range D:K starting with Row 3 where the following 2 conditions are met:
    • Start counting in the during the starting week (Column B)
    • AND Stop counting when the headcount (Column A) is achieved
  • Column C is where the formula will live
Screenshot for MrExcel.png


Example:
  • Row 3: I want to know how many weeks it takes to meet or exceed 100 headcount (A3), starting with week 2 (B3)
    • Answer: Should be 5 because it starts with E3, counts that week and stops at I3

I'm pretty sure this is a combo of a COUNTIFS and Index Match but for some reason I just can't get it right.

Thanks so much!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
try this...
MrExcel_20220614.xlsx
ABCDEFGHIJK
1
2HeadcountStart WkWks to Reach12345678
3100252040608090100120150
412042304070100150180220290
Sheet8
Cell Formulas
RangeFormula
C3:C4C3=MATCH(1,--(D3:K3>=A3),0)-B3+1
 
Upvote 0
try this...
MrExcel_20220614.xlsx
ABCDEFGHIJK
1
2HeadcountStart WkWks to Reach12345678
3100252040608090100120150
412042304070100150180220290
Sheet8
Cell Formulas
RangeFormula
C3:C4C3=MATCH(1,--(D3:K3>=A3),0)-B3+1

Thank you @KRice, this works!
 
Upvote 0
You're welcome...happy to help!

@KRice One minor wrinkle. There are cases where the Headcount is already met at the starting week and the headcount decreases.

I included an example in Row 6. Using the above formula formula the output is a -3. I'm hoping there's a way to tweak the formula to recognize that the headcount was met on week 5 and output a 1.

Would that be possible? Thanks again, I really appreciate it!

Screenshot for MrExcel v2.png
 
Upvote 0
Oh...I had not anticipated that. So are you saying then that this would be an exception to the rule? That is, if you adhere strictly to the rule and begin counting at the "start week" of 5 (for the row 6 case), you'll never reach the target headcount. So you want a week number returned in those instances, even if it is before the "start" week?

Excel Formula:
=LET(cidx,MATCH(1,--(D3:K3>=A3),0),IF(cidx<B3,cidx,cidx-B3+1))

Also, what should happen if the headcount is never reached?
 
Upvote 0
To illustrate my question, consider the following options. The green formulas return the week at which the headcount is reached IF that week occurs prior to the "start" week. The blue formulas return a "1" instead, indicating that by the time we begin counting at the start week (even if the value in that start week is too small), we've already passed the actual week where the headcount was reached. The orange formula is the blue formula except an extra error trap is added to address the case where no match is found, probably because the headcount is never reached.
MrExcel_20220614.xlsx
ABCDEFGHIJK
7HeadcountStart WkWks to Reach12345678
83051504030252015105
930531020304050607080
103051504030252015105
1130511020304050607080
12905not found1020304050607080
Sheet8
Cell Formulas
RangeFormula
C8:C9C8=LET(cidx,MATCH(1,--(D8:K8>=A8),0),IF(cidx<B8,cidx,cidx-B8+1))
C10:C11C10=LET(cidx,MATCH(1,--(D10:K10>=A10),0),IF(cidx<B10,1,cidx-B10+1))
C12C12=IFERROR(LET(cidx,MATCH(1,--(D12:K12>=A12),0),IF(cidx<B12,1,cidx-B12+1)),"not found")
 
Upvote 0
Oh...I had not anticipated that. So are you saying then that this would be an exception to the rule? That is, if you adhere strictly to the rule and begin counting at the "start week" of 5 (for the row 6 case), you'll never reach the target headcount. So you want a week number returned in those instances, even if it is before the "start" week?

Excel Formula:
=LET(cidx,MATCH(1,--(D3:K3>=A3),0),IF(cidx<B3,cidx,cidx-B3+1))

Also, what should happen if the headcount is never reached?

Your revised formula worked! I'll add an IFERROR if the headcount is never reached to leave the cell blank.

Thanks again, this helped immensely!
 
Upvote 0
Good...so did you want the green version or the blue version?...one returns the column index, the other returns a "1" for the exceptional cases.
 
Upvote 0
Good...so did you want the green version or the blue version?...one returns the column index, the other returns a "1" for the exceptional cases.

Thie formula below works great. I'll spot check again but I think that solves what I'm looking to achieve.

=LET(cidx,MATCH(1,--(D3:K3>=A3),0),IF(cidx<B3,cidx,cidx-B3+1))
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

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