+ Reply to Thread
Results 1 to 11 of 11

How to Count for each category

Hybrid View

afriedman How to Count for each category 06-21-2011, 12:43 PM
Colin Legg Re: How to Count for each... 06-21-2011, 12:48 PM
afriedman Re: How to Count for each... 06-21-2011, 12:52 PM
Colin Legg Re: How to Count for each... 06-21-2011, 12:56 PM
afriedman Re: How to Count for each... 06-21-2011, 01:04 PM
Colin Legg Re: How to Count for each... 06-21-2011, 01:20 PM
afriedman Re: How to Count for each... 06-21-2011, 02:02 PM
afriedman Re: How to Count for each... 06-21-2011, 03:37 PM
Colin Legg Re: How to Count for each... 06-21-2011, 03:47 PM
afriedman Re: How to Count for each... 06-21-2011, 05:29 PM
Colin Legg Re: How to Count for each... 06-21-2011, 05:33 PM
  1. #1
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: How to Count for each category

    (1)

    The - is a unary minus operator. SUMPRODUCT processes numbers well, but it can't handle logical types such as TRUE or FALSE.

    A test such as ($B$5:$B$12=$F5) returns an array of logical values, such as {TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;TRUE}. SUMPRODUCT can't compute this array so we coerce the logical types into number types by performing an arithmetic operation on it.

    For each element in the array:
    -TRUE becomes -1, so --TRUE becomes 1
    -FALSE becomes 0, so --FALSE becomes 0

    So for the whole array:

    If
    ($B$5:$B$12=$F5) gives {TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;TRUE}

    then
    --($B$5:$B$12=$F5) gives
    {1;1;1;0;0;0;0;1}


    (2)
    Yes, of course, but you lose flexibility. The formula would be like:
    =SUMPRODUCT(--($B$5:$B$12=$F5),--($C$5:$C$12>=1),--($C$5:$C$12<=5))
    You'll need to adjust accordingly for each number grouping.

    (3)
    SUMPRODUCT is an expensive formula when it is used like this. Too many formulas like this and your workbook calculation will become slow.

    Additionally, a pivot table will automatically generate a distinct list of categories for you: with the formula solution, if a new category appears then you'll have to manually add it to your summary table, whereas a pivot table will do it automatically. Note that the pivot table can be set up to reference a dynamic named range/table so it will automatically account for changes in the source data size. The same sort of thing is true for the number groupings - if a new number grouping (say 15-20 or whatever) is necessary then you'll have to recognise that and manually add in new formulas; the pivot table would do that automatically.

    Finally, people will generally understand the pivot table more easily than the SUMPRODUCT formula. The SUMPRODUCT formula is complicated!
    Last edited by Colin Legg; 06-21-2011 at 01:26 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

  2. #2
    Registered User
    Join Date
    12-09-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to Count for each category

    SO let me throw one more layer of complexity at you.

    Say I have 3 columns with numbers. And I want to get that same Total between 1-5, 6-10 etc but agragated for categories Number's 1, Number's 2 Number's 3.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-09-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to Count for each category

    Because when I put it into a Pivot with the 3 columns, it doesn't work properly, and the formula wont read the 3 arrays....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1