+ Reply to Thread
Results 1 to 5 of 5

How to count the number of times an expression is true

  1. #1
    Registered User
    Join Date
    11-05-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    31

    How to count the number of times an expression is true

    Hi all,

    hopefully a quick one.

    In Excel 2003 I need to be able to count the number of times in two columns that value 1 is larger than value 2. So in my attachment C11 to C15 all equal 10 and D11 to D15 equal 5,10,15,20 & 5 respectively. In this case there are 2 occurances of Cx been greater than Dx and 3 occasions when Cx is greater or equal to Dx.

    In my real world spreadsheet there can be anything up to 2000 rows to compare.

    Can the count of all rows in column C being greater than column D be returned from a single equation?

    Many thanks,

    Sherlock99.
    Attached Files Attached Files

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How to count the number of times an expression is true

    =SUMPRODUCT(--($C$7:$C$11>$D$7:$D$11))
    and
    =SUMPRODUCT(--($C$7:$C$11>=$D$7:$D$11))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    11-05-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: How to count the number of times an expression is true

    Thats great martindwilson. Thanks for the swift reply.

    it does what I need. I am able to change the values to be 1 - 2000 as it will never exceed 2000. I am curious however.

    What if you didnt know how many rows you were dealing with?. How would you compare the whole of column C with the whole of column D?.

    When I try

    =SUMPRODUCT(--($C:$C>$D:$D))

    I get a #NUM error. Have I got the syntax correct?

    Regards,

    sherlock99.

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: How to count the number of times an expression is true

    Hi Sherlock,

    In Excel 2003 SUMPRODUCT can't handle entire column references like that. It's best to keep the ranges as small as possible, otherwise the formula(e) will be slow to calculate. If you didn't know how many rows you were dealing with, you could create a dynamic named range (or a list, or table - depending on Excel version) which would automatically expand or contract as the data size changed - note that the two ranges must be the same size.
    Hope that helps,

    Colin

    RAD Excel Blog

  5. #5
    Registered User
    Join Date
    11-05-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: How to count the number of times an expression is true

    Thanks for the reply Colin.

    I shouldn't need this degree of complication but its good to know the limitations of a formula.

    Regards,

    sherlock99.

+ 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