+ Reply to Thread
Results 1 to 5 of 5

Count text strings that meet a condition

  1. #1
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Count text strings that meet a condition

    Hello, please see the formula's on sheet 6 in the attached workbook. I am trying to count the amount of times the yellow cells appear in the array named "data" on the same lines as the blue cells appear in the array named "breadtype". Obviously this is failing as the arrays are different sizes. Does anyone know of any way to do this?

    Thanks for any help you can give!
    Clayton Grove
    Attached Files Attached Files
    Last edited by dcgrove; 09-14-2010 at 03:38 PM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Need help counting text strings that meet a condition in Arrays of different size

    This formula works if you don't have errors (#N/A) in the ranges,

    =SUMPRODUCT((data=B$1)*(breadtype=$A2))

    ...... so either eliminate all errors or you can switch to this "array formula"

    =SUM(IF(ISNUMBER((data=B$1)*(breadtype=$A2)),(data=B$1)*(breadtype=$A2)))

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

  3. #3
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Count text strings that meet a condition

    Taking out the errors worked although I am not sure why or how the formula works. Everything I have read about the sumproduct formula is that the arrays that are being evaluated must be the same size.


    When using the SUMPRODUCT function, all arrays must be the same size, as corresponding members of each array are multiplied by each other.

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Count text strings that meet a condition

    Yes, arrays do have to be the same size in SUMPRODUCT.

    There's a subtle difference in the syntax here that means that the arrays are multiplied first....and SUMPRODUCT then technically operates on only a single array.

    You can see this with a simple example. Fill A1:C5 with numbers and try this formula

    =SUMPRODUCT(A1:A5,B1:C5)

    You get a #VALUE error because A1:A5 is not the same size as B1:C5.....but if you do this

    =SUMPRODUCT(A1:A5*B1:C5)

    You get a result because multiplying those ranges using matrix multiplication gives you a single 2x5 matrix....and SUMPRODUCT effectively just sums the resultant single array. In these cases you don't even need SUMPRODUCT, SUM would be sufficient because you are only summing a single array, i.e.

    =SUM(A1:A5*B1:C5)

    will do the trick.....although it needs to be "array entered" with CTRL+SHIFT+ENTER....similarly you could use

    =SUM((data=B$1)*(breadtype=$A2))

    array entered

  5. #5
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Count text strings that meet a condition

    Thanks for the explanation!

+ 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