You are here:

# Excel/Count formula assistance

Question

Count scenario
QUESTION: Hi Tom

Attached is a scenario.  I've attached it as a gif format, however it was originally prepared in excel.  It contains several cost centres with data for several weeks (most recent week 1st).  I need to be able to count 4 different values from the range.
1.  The number of times in a row from the most recent week that I am underbudget.
2.  The number of times within that range that I am 2 or more underbudget.
3.  The number of times in total over the full range that I am underbudget.
4   The number of times in total over the full range that I am 2 or more underbudget.
Attached is the scenario.  I will need a different formula for columns B,C,D&E.
Kindest regards
Paul Hancock

B2: =IFERROR(MATCH(-0.01,\$F2:\$L2,1),0)
C2: =IFERROR(COUNTIF(OFFSET(\$E2,0,1,1,MATCH(-0.01,\$F2:\$L2,1)),"<=-2"),0)
D2: =COUNTIF(\$F2:\$L2,"<0")
E2: =COUNTIF(\$F2:\$L2,"<=-2")

then select B2:E2 and drag fill down to row 9

I put your data in a worksheet and used the above formulas to reproduce the results you show.

Assumes Excel 2007 or later.

--
Regards,
Tom Ogilvy

---------- FOLLOW-UP ----------

Version 2
QUESTION: Hi Tom
Thanks the the formula yesterday.  When I've put the formula into my big spreadsheet I've been designing at work the formula in column B doesn't fit all scenarios.  Refering back to the gif that I sent previously (which I've re-attached with a change to demonstrate) if cost centre 3, week 7 were a positive figure with the other weeks remaining unchanged I would expect cell B4 and C4 to change to 0.  Unfortunately they don't.  Also, week 8 columns B and C are coming out with incorrect figures.  I would expect both to show 0.  I've highlighted both on the gif.
Kind Regards
Paul

>Also, week 8 columns B and C are coming out with incorrect figures.

I guess you mean workcenter 8 when  you say week 8.

These modifications fixed all the problems you described:

B2:  =IF(\$F2>=0,0,IFERROR(MATCH(-0.01,\$F2:\$L2,1),0))
so if the value in column F (week 07) is not negative, then b2 should show zero.

C2: =IF(B2=0,0,IFERROR(COUNTIF(OFFSET(\$E2,0,1,1,MATCH(-0.01,\$F2:\$L2,1)),"<=-2"),0))
You originally used the term "this range" which I take to mean the range identified in the formula in column B.  So if that range is zero, then C2 should be zero as well.

these changes fix the problem with center 8 as well.  Let me know if you find another problem.

--
Regards,
Tom Ogilvy

---------- FOLLOW-UP ----------

QUESTION: Hi Tom
Thanks for the reply.  I think we are close to what I was looking for.  In column B I need the formula to stop counting as soon as it meets a figure that isn't negative.  EG

If the Budget variance Figures were:
(5),(3),(1),2,(3),5,(2)
I would need the forumla in column B to stop counting when it came across the number 2, giving a count of 3 in column B.

Kind Regards

Paul Hancock

Paul Hancock,

3          -5   -3   -1   2   -3   5   -2

the 3 is the result from the formula in column B.

=IF(\$F12>=0,0,IFERROR(MATCH(-0.01,\$F12:\$L12,1),0))
(I was testing in row 12)

How about contacting me directly at twogilvy@msn.com

so you can send a file and explain what you see as a problem.

--
Regards,
Tom Ogilvy

Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Thanks Tom I'm on annual leave tomorrow so I shall contact you next week on the email you've provided next week. Thanks very much for your assistance. Best Regards Paul

This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

#### Tom Ogilvy

##### Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

##### Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.