Count number of times a value appears in role??

kelvin2088

Board Regular
Joined
Mar 11, 2010
Messages
78
Hi everyone,

I have a dataset like this:
0
1
1
1
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0

is there any formula that can help me count maximum number of times each value appears in role? like in this case, "0" appeared in role for maximum 7 times, "1" appeared in role for maximum 3 times
 
That is good that it works!

For the example I gave, this is a better formula:

=MAX(FREQUENCY(IF(A1:A24=0,IF(A1:A24<>"",ROW(A1:A24))),IF(A1:A24<>0,IF(A1:A24<>"",ROW(A1:A24)))))


It will give the same results, but is a shorter formula.
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Okay, you want the why? I’ll take a crack at it.

Data set =

Excel Workbook
AB
1=00
2<>01
3empty cell
4<>01
5<>01
6=00
7=00
8=00
9formula ="
10=00
11=00
12<>01
13=00
14<>01
15=00
16=00
17formula ="
18=00
19empty cell
20empty cell
21=00
22=00
23=00
24=00
...


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
The FREQUENCY function has 2 arguments:
<o:p></o:p>
=FREQUENCY(data_array,bins_array)
<o:p></o:p>
The FREQUENCY function counts data items (data_array) that fall within a given set of categories (bins_array). If data items (data_array) were this set:
<o:p></o:p><o:p></o:p>
{1;FALSE;FALSE;FALSE;FALSE;6;7;8;FALSE;10;11;FALSE;13;FALSE;15;16;FALSE;18;FALSE;FALSE;21;22;23;24}<o:p></o:p><o:p></o:p>

And you gave it the categories (bins_array):
<o:p></o:p><o:p></o:p>
row<=2<o:p></o:p>
2< row<= 4<o:p></o:p>
4< row<= 5<o:p></o:p>
5< row<= 12<o:p></o:p>
12< row<= 14<o:p></o:p>
14< row
<o:p></o:p>
These categories would get a count like this:
<o:p></o:p><o:p></o:p>
row<=2 counts #s 1 to get ==>> 1<o:p></o:p>
2< row<= 4 counts #s to get ==>> 0<o:p></o:p>
4< row<= 5 counts #s to get ==>> 0<o:p></o:p>
5< row<= 12 counts #s 6,7,8,10,11 to get ==>> 5<o:p></o:p>
12< row<= 14 counts #s 13 to get ==>> 1<o:p></o:p>
14< row counts #s 15,16,18,21,22,23,24 to get ==>> 7
<o:p></o:p>
The max of the numbers 1,0,0,5,1,7 is 7. That is the answer.
<o:p></o:p>
If you followed all that, then we can look at how the formula is working.
<o:p></o:p><o:p></o:p>
To see in more detail, here is the formula:
<o:p></o:p>
=FREQUENCY(data_array,bins_array)
<o:p></o:p>
Data_array = IF(B1:B24=0,IF(B1:B24<>"",ROW(B1:B24)))
<o:p></o:p>
Bins_array = IF(B1:B24<>0,IF(B1:B24<>"",ROW(B1:B24)))
<o:p></o:p>
To get:
<o:p></o:p>
=MAX(FREQUENCY(IF(B1:B24=0,IF(B1:B24<>"",ROW(B1:B24))),IF(B1:B24<>0,IF(B1:B24<>"",ROW(B1:B24)))))
<o:p></o:p>
Data_array = IF(B1:B24=0,IF(B1:B24<>"",ROW(B1:B24))) says: If any values are 0 and not blank then give me the row number. So this evaluates to:
<o:p></o:p>
{1;FALSE;FALSE;FALSE;FALSE;6;7;8;FALSE;10;11;FALSE;13;FALSE;15;16;FALSE;18;FALSE;FALSE;21;22;23;24}<o:p></o:p>

Bins_array = IF(B1:B24<>0,IF(B1:B24<>"",ROW(B1:B24))) says: If any values are not 0 and not blank then give me the row number. So this evaluates to:<o:p></o:p>

{FALSE;2;FALSE;4;5;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;12;FALSE;14;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE}<o:p></o:p>

So these numbers: 2,4,5,12,14 are the upper amounts for each category, with one extra category added to the end to catch any values that are greater than the biggest bin value to get:
<o:p></o:p>
row<=2<o:p></o:p>
2< row<= 4<o:p></o:p>
4< row<= 5<o:p></o:p>
5< row<= 12<o:p></o:p>
12< row<= 14<o:p></o:p>
14< row
<o:p></o:p>

FREQUENCY is programmed to create categories like this from bin numbers.

The formula then looks like this:
<o:p></o:p>
=MAX(FREQUENCY({1;FALSE;FALSE;FALSE;FALSE;6;7;8;FALSE;10;11;FALSE;13;FALSE;15;16;FALSE;18;FALSE;FALSE;21;22;23;24},{FALSE;2;FALSE;4;5;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;12;FALSE;14;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE}))<o:p></o:p>

Then like this:<o:p></o:p><o:p></o:p>
=MAX({1;0;0;5;1;7})
<o:p></o:p>
And finally:
<o:p></o:p><o:p></o:p>
Max number of successive 0s = 7.

I hope that helps.<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,321
Members
449,154
Latest member
pollardxlsm

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