Help with CountIf?

  • Thread starter Thread starter terrymac52
  • Start date Start date
T

terrymac52

I have a column of numbers that may look like this:

Column A
1
2
3
4
x
1
2
x
1
2
3
x

I'm looking for a way to return the number above the x, and to count
them up, in other words, how many 4's, 2,s 3's etc. Thanks in advance
for any help.

Terry
 
To count the number of 4's, try...

=SUMPRODUCT(--(A2:A12="x"),--(A1:A11=4))

Hope this helps!
 
Perhaps a quick and easy way is simply to use a Pivot Table (PT) ?

Taking your sample data in col A in Sheet1 (say)

Insert a new row1, and put a label in A1, say: Label
Click anywhere within the table
Click Data > Pivot Table Report > Next > Next

In step 3 of the wizard:
Drag and drop Label in the ROW area
Drag and drop Label in the DATA area
(It'll appear as "Count of Label")

Click Finish

The PT will be created in a new sheet to the left of Sheet1
It'll appear as:

Count of Label
Label Total
1 3
2 3
3 2
4 1
x 3
Grand Total 12

And you could, if desired, hide the non-numeric "x" item
In the PT, just double-click on "Label"
In the PT Field dialog, select "x" under Hide items > OK
You'll get:

Count of Label
Label Total
1 3
2 3
3 2
4 1
Grand Total 9
 
Max wrote...
Perhaps a quick and easy way is simply to use a Pivot Table (PT) ?
....

You don't believe in reading OPs' postings carefully? How would pivot
tables be able to identify the entries in cells above cells evaluating
to "x"?

Using a different list, such as

1
2
x
1
2
3
4
x
1
x
1
2
x

For starters, the OP is requesting to identify 2, 4 and 1 as
categories. Then the OP is requesting to count either the 2s, 4s and 1s
immediately above the cells containing the x's or could all 2s, 4s and
1s in the list.

First, identifying the cells immediately above x's. If the list were
named LST and the category values would appear in column C starting in
cell C1, enter the formulas

C1 [array formula]:
=INDEX(LST,MATCH(TRUE,(OFFSET(LST,1,0)="x"),0))

C2 [array formula]:
=INDEX(LST,MATCH(1,(OFFSET(LST,1,0)="x")*(COUNTIF(C$1:C1,LST)=0),0))

Fill C2 down until the formula returns #N/A. Using my sample data,
there would be only 3 categories - 2, 4 and 1 - so C1:C3 would evaluate
to 2, 4 and 1, respectively, and C4 to #N/A.

To count just the 2s, 4s and 1s appearing immediately above the x's,
select D1:D3 and use FREQUENCY.

D1:D3 [array formula]:
=FREQUENCY(IF(OFFSET(LST,1,0)="x",LST),C1:C3)

To count all 2s, 4s and 1s in LST, use COUNTIF.

D1:
=COUNTIF(LST,C1)

and fill D1 down into D2:D3.
 
Harlan Grove said:
You don't believe in reading OPs' postings carefully?
How would pivot tables be able to identify the
entries in cells above cells evaluating to "x"?

Probably more a case of a well-intentioned guess going awry <g>
 
Max wrote...
....
Probably more a case of a well-intentioned guess going awry <g>

How good could your intentions be if you don't read the OP's message
carefully?
 
Harlan Grove said:
How good could your intentions be
if you don't read the OP's message carefully?

As good as someone w/o any pretensions can be
(Remember I did use the word "Perhaps .. ")

OP:
.. a way to return the number above the x,
and to count them up, in other words,
how many 4's, 2,s 3's etc.

well, think I did read the post with care,
but guessed (incorrectly? - only the OP can confirm this)
from the OP's lines above,
e.g. there could be a missing "s" in the word "number" in
the number above the x

Do hope the OP responds somewhere in this thread
to put me once and for all out of this misery <g>
 
I should have elaborated further. The X's in the column signify an
occurance. The numbers indicate days until the occurance happens. The
numbers can go much higher than 1,2,3,4, etc. The column can get quite
long. I was looking to find out how many days happened until the
occurance, in other words, the number above the x, and also to tell me
how many 4's, or 1's etc. I might have four 4's three 8's and so on. I
realize that I would have to copy the formula to multiple cells below
the column.

Sorry I took so long to get back, got called out of town on business.

Thanks.
 
Maybe this is what you're looking to do..........

In B2 put this formula and copy down............

=IF(A2="x",A1,"")

Then do Copy > PasteSpecial > Values, on column B

Then Tools > DataAnalysis > Histogram, on column B to give you the
distribution of 4's, etc.

Vaya con Dios,
Chuck, CABGx3
 
Thanks for the feedback!
Pl disregard my suggestion.

See thr insights / offerings from others, especially Harlan
 
Back
Top