Count specific values in an unsorted, random data base

NewExcel25

New Member
Joined
Sep 22, 2013
Messages
4
How does one count the number of x and y values (occurring in same row) in this array?

Time1 x a b c d
Time2 b c x y a
Time3 x a y d b
Time4 a b c d e
Time5 y d a x d
Time6 c y a d b

Note all of the variables above are positive numbers.

The answer should be 3.

Thank you,
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How does one count the number of x and y values (occurring in same row) in this array?

Time1 x a b c d
Time2 b c x y a
Time3 x a y d b
Time4 a b c d e
Time5 y d a x d
Time6 c y a d b

Note all of the variables above are positive numbers.

The answer should be 3.

Thank you,

Data is in A2:F7, with the row labels in A2:A7 and numbers in B2:F7.

x and y, the numbers to look for, are in H2:I2.

K2, control+shift+enter, not just enter:
Rich (BB code):
=SUM((MMULT((COUNTIF(OFFSET(B2:F7,ROW(B2:F7)-ROW(B2),0,1),H2:I2)>0)+0,
    TRANSPOSE(COLUMN(H2:I2)>0)+0)=COUNT(H2:I2))+0)
following a solution to a problem posed by Stephen_IV...
 
Upvote 0
Data is in A2:F7, with the row labels in A2:A7 and numbers in B2:F7.

x and y, the numbers to look for, are in H2:I2.

K2, control+shift+enter, not just enter:
Rich (BB code):
=SUM((MMULT((COUNTIF(OFFSET(B2:F7,ROW(B2:F7)-ROW(B2),0,1),H2:I2)>0)+0,
    TRANSPOSE(COLUMN(H2:I2)>0)+0)=COUNT(H2:I2))+0)
following a solution to a problem posed by Stephen_IV...

Wow, thank you very much. As a followup, if the values for H2 and I2 are not next to each other? i.e., a comparison of whole range of values.
So, on another sheet, 200 values across and 200 values down. The above equation would be in each of the cells of the corresponding matrix.

For Cell B2:
=SUM((MMULT((COUNTIF(OFFSET(DataSet,ROW(DataSet)-ROW(DataSet),0,1),B$1:$A2)>0)+0,TRANSPOSE(COLUMN(B$1:$A2)>0)+0)=COUNT(B$1:$A2))+0)

So the question is, what is the correct syntax for B$1:$A2 part of the equation? Where DataSet is the named B2:F7.
 
Upvote 0
Wow, thank you very much. As a followup, if the values for H2 and I2 are not next to each other? i.e., a comparison of whole range of values.
So, on another sheet, 200 values across and 200 values down. The above equation would be in each of the cells of the corresponding matrix.

For Cell B2:
=SUM((MMULT((COUNTIF(OFFSET(DataSet,ROW(DataSet)-ROW(DataSet),0,1),B$1:$A2)>0)+0,TRANSPOSE(COLUMN(B$1:$A2)>0)+0)=COUNT(B$1:$A2))+0)

So the question is, what is the correct syntax for B$1:$A2 part of the equation? Where DataSet is the named B2:F7.

Please try to be specific by means of a scaled-down but representative data.
 
Upvote 0
This is what I was using for a simple data test case tab:
9/1/2013 1 14 2 40 53 20
9/2/2013 16 2 24 39 42 46
9/3/2013 25 32 35 50 1 46
9/4/2013 4 22 3 2 38 42
9/5/2013 2 7 36 42 44 39

Dataset = B2:G5

Test Case Tab:
12
39
Formula referencing B1 & A2

<tbody>
</tbody>
Formula referencing C1 & A2

<tbody>
</tbody>
50
Formula referencing B1 & A3

<tbody>
</tbody>
Formula referencing C1 & A3

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
This is what I was using for a simple data test case tab:
9/1/2013 1 14 2 40 53 20
9/2/2013 16 2 24 39 42 46
9/3/2013 25 32 35 50 1 46
9/4/2013 4 22 3 2 38 42
9/5/2013 2 7 36 42 44 39

Dataset = B2:G5

Test Case Tab:
1
2
39
Formula referencing B1 & A2

<TBODY>
</TBODY>

Formula referencing C1 & A2

<TBODY>
</TBODY>

50
Formula referencing B1 & A3

<TBODY>
</TBODY>

Formula referencing C1 & A3

<TBODY>
</TBODY>


<TBODY>
</TBODY>


1
2
39
0
2
50
1
0

<TBODY>
</TBODY>

Since we have 2 item sets to test for:

B2, control+shift+enter, not just enter, copy across, and down:
Rich (BB code):
=SUM((MMULT((COUNTIF(OFFSET(DataSet,ROW(DataSet)-ROW(B2),0,1),
  CHOOSE({1,2},B$1,$A2))>0)+0,{1;1})=2)+0)
 
Upvote 0
Hurray! Thank you, that works!.

You are welcome.

Since we use a named range, it's nicer to express the ROW(B2) bit also as a named range, that is:

ROW(INDEX(DataSet,1,1))

The formula in full:
Rich (BB code):
=SUM((MMULT((COUNTIF(OFFSET(DataSet,ROW(DataSet)-ROW(INDEX(DataSet,1,1)),0,1),
  CHOOSE({1,2},B$1,$A2))>0)+0,{1;1})=2)+0)
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

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