+ Reply to Thread
Results 1 to 9 of 9

Thread: How to SUMPRODUCT with non-repeated serial number*item

  1. #1
    Valued Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    225

    Question How to SUMPRODUCT with non-repeated serial number*item

    Hi,

    I have attached a sample table. I got the total number fruits used but now I need to split the number of Apples and Oranges used. Some apples are the same that's why the serial number is the same. May I know how to I count the number of individual fruit used?
    Attached Files Attached Files

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: How to SUMPRODUCT with non-repeated serial number*item

    Well, assuming a Serial Number has a 1:1 relationship with "Fruit" (ie serial number 1 would only ever be Apple and never both Apple & Orange) then:

    =SUMPRODUCT((B3:B12="Apple")/COUNTIF(A3:A12,A3:A12&""))

  3. #3
    Valued Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    225

    Re: How to SUMPRODUCT with non-repeated serial number*item

    Hi, thanks! It works!

    But what does COUNTIF(A3:A12,A3:A12&"") actually do? I break it down and copy to a cell and it shows value 0. What does the A12&"" do?

  4. #4
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: How to SUMPRODUCT with non-repeated serial number*item

    The use of &"" is to account for possibility of blank cells in the range specified.

    The function as a whole is used to generate an array of COUNTIF results - one for each cell referenced in the A3:A12&""

    If in doubt work through the example using the Evaluate tool

    =SUMPRODUCT((B3:B12="Apple")/COUNTIF(A3:A12,A3:A12&""))

    we know that the first part will generate an Array of:

    {TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;FALSE;FALSE;FALSE}

    ie one Boolean for each cell in range B3:B12 where TRUE means Bn = Apple

    We know from above that our COUNTIF will generate an array of COUNTIF results, one for each criteria (A3:A12&"") specified thus we end up with a 2nd array of:

    {3;3;3;2;2;1;1;1;1;1}

    We know that the act of division will coerce our Booleans from TRUE/FALSE to 1/0 respectively thus we end up with the following values:

    {0.333333333333333;0.333333333333333;0.333333333333333;0.5;0.5;1;1;0;0;0}

    (ie TRUE/3; TRUE/3; TRUE/3; TRUE/2; TRUE/2; TRUE/1; TRUE/1; FALSE/1; FALSE/1; FALSE/1)

    The SUM of those values is then the result of the unique terms - ie 4.

    This ONLY works because the serial number : fruit relationship is 1:1 ... if a serial number could apply to multiple fruits then you would need a more sophisticated approach than the above.
    Last edited by DonkeyOte; 07-23-2010 at 05:00 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    225

    Question Re: How to SUMPRODUCT with non-repeated serial number*item

    Hi, sorry, I'm still confused. Anyway, where do I find the Evaluate tool in excel?
    I encounter another problem when I try to combine this solution with another solution from another thread. Do I continue posting from here or start a new thread?

  6. #6
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: How to SUMPRODUCT with non-repeated serial number*item

    Quote Originally Posted by Lewis Koh
    I'm still confused
    I can't really detail the example any more fully than I did previously I'm afraid.

    It's a pretty basic concept I think ?
    In essence you're apportioning 1 based on the frequency with which a given value appears in the dataset.
    This means that when the apportionments are aggregated the sum is 1 thereby mimicking a unique count.

    Quote Originally Posted by Lewis Koh
    where do I find the Evaluate tool in excel?
    I missed the fact you are using XL2000 - I don't believe the Evaluate tool was introduced until 2002/3.

    Given the above I'm not sure if you can use the F9 route in XL2000 either ?ie highlight a section of the formula you're interested in within the Formula Bar and press F9

    Quote Originally Posted by Lewis Koh
    I encounter another problem when I try to combine this solution with another solution from another thread. Do I continue posting from here or start a new thread?
    Perhaps best to start a new thread - reference the other threads if you deem them significantly important to the new question.

  7. #7
    Valued Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    225

    Re: How to SUMPRODUCT with non-repeated serial number*item

    Hi, I just realized there is a flaw in my template. Attached is my example. On column C, I'll indicate "NIL" so that I won't count the items. How do I do the counting of only Apples with no NIL on column C?
    Attached Files Attached Files

  8. #8
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: How to SUMPRODUCT with non-repeated serial number*item

    Again it depends on the relationship between NIL and Serial.

    If (as implied by sample) the relationship is 1:1 - all items of serial n share the same status in C (be it NIL or other) then:

    =SUMPRODUCT((($B$3:$B$12="Apple")*($C$3:$C$12<>"NIL"))/COUNTIF($A$3:$A$12,$A$3:$A$12&""))
    If that is not the case - ie items of serial n may be both NIL & non-Nil simultaneously then:

    =SUMPRODUCT((($B$3:$B$12="Apple")*($C$3:$C$12<>"NIL"))*(MATCH($A$3:$A$12,$A$3:$A$12,0)=(ROW($A$3:$A$12)-ROW($A$3)+1)))
    though note the above is still based on 1:1 relationship between serial:fruit (as before)

  9. #9
    Valued Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    225

    Re: How to SUMPRODUCT with non-repeated serial number*item

    ok, got it. Thanks! :-)

+ 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.2.0