Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this "array formula"</p> <p><code>=SUM(IF(FREQUENCY(IF(A$1:A$11=C1,IF(B$1:B$11&lt;&gt;"",MATCH(B$1:B$11,B$1:B$11,0))),ROW(B$1:B$11)-ROW(B$1)+1),1))</code></p> <p>confirmed with <code>CTRL+SHIFT+ENTER</code></p> <p>Where C1 is the first category to count for. Copy formula down for all categories</p> <p><strong>Explanation</strong></p> <p>The basic idea of the formula is that the first <code>IF</code> is a "filter" to ensure that you only look at B values if A value = C1, the second <code>IF</code> filters out blanks in B, otherwise the <code>MATCH</code> gives the position of the first match for that value in B (thus giving the same number for the same values)</p> <p>The result of the <code>IFs</code> is the first part of <code>FREQUENCY</code> function. The "bins" in <code>FREQUENCY</code> are formed by the <strong>ROW-ROW+1</strong> part which gives you a range of numbers 1 to n which will encompass the whole range of values that <code>MATCH</code> might give.</p> <p>Now we just need to count the number of different numbers returned by the <code>IF</code>s (as that will be equal to the number of different values in B for your criterion), so the final 1 in the formula is assigned to each non-zero value in <code>FREQUENCY</code> and the result is summed.</p> <p>In detail for your example where C1 = A this part</p> <p><code>=IF(A$1:A$11=C1,IF(B$1:B$11&lt;&gt;"",MATCH(B$1:B$11,B$1:B$11,0)))</code></p> <p>results in this array</p> <p><code>{1;2;2;4;FALSE;FALSE;FALSE;8;9;FALSE;FALSE}</code></p> <p>FALSE values where col A &lt;> "A" otherwise numbers from <code>MATCH</code> giving the position of the first match for each value - notice 2 appears twice because foo appears twice, firstly in row 2</p> <p>and the <code>ROW(B$1:B$11)-ROW(B$1)+1</code> part gives you this array</p> <p><code>{1;2;3;4;5;6;7;8;9;10;11}</code></p> <p>so now the formula looks like this</p> <p><code>=SUM(IF(FREQUENCY({1;2;2;4;FALSE;FALSE;FALSE;8;9;FALSE;FALSE},{1;2;3;4;5;6;7;8;9;10;11}),1))</code></p> <p>So <code>FREQUENCY</code> puts the values in the first array into the relevant "bins" and formula now resolves to this</p> <p><code>=SUM(IF({1;2;0;1;0;0;0;1;1;0;0;0},1))</code></p> <p>Note that the array returned by <code>FREQUENCY</code> sums to 6 (six rows with value "A") but there are only 5 non-zero numbers, denoting the five different values for criterion "A".</p> <p>Now the last IF returns a 1 for each non-zero value and <code>SUM</code> function sums those to get 5</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload