+ Reply to Thread
Results 1 to 7 of 7

Thread: Looking for counts from an array

  1. #1
    Registered User
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    38

    Looking for counts from an array

    Evening all,

    I have tried to use the countifs function to find the totals of 1s a 4s in the table.
    No luck yet.

    Table attached.

    Cheers,
    John.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,461

    Re: Looking for counts from an array

    Johnmitch93,

    The formula in cell B27:
    =SUMPRODUCT(($A$2:$A$25="NORTH")*($B$2:$F$25=4))

    returns:
    4


    The formula in cell B28:
    =SUMPRODUCT(($A$2:$A$25="NORTH")*($B$2:$F$25=1))

    returns:
    10
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Looking for counts from an array

    Stanley,

    That's good stuff, mate. Ta very much.

    Is there an explaination why the countifs is no good? I was sure I had done it that way before.
    Maybe my memory...

    John.

  4. #4
    Valued Forum Contributor Haseeb A's Avatar
    Join Date
    05-24-2011
    Location
    India | Kwt
    MS-Off Ver
    2007
    Posts
    1,453

    Re: Looking for counts from an array

    Hello John, All the ranges must be in same number of rows & columns, if you have multiple conditions.

    Excel help says,

    Each additional range must have the same number of rows and columns as the criteria_range1 argument. The ranges do not have to be adjacent to each other
    Or, you can use COUNTIFS with OFFSET. Note OFFSET is a volatile function

    =SUMPRODUCT(COUNTIFS(A2:A25,"NORTH",OFFSET(B2:B25,0,{0,1,2,3,4}),4))

    This is basically doing,

    =COUNTIFS(A2:A25,"NORTH",B2:B25,4)+COUNTIFS(A2:A25,"NORTH",C2:C25,4)+...COUNTIFS(A2:A25,"NORTH",E2:E 25,4)
    Last edited by Haseeb A; 01-27-2012 at 05:53 PM. Reason: Typo...
    HTH; Haseeb

    If your problem is solved, please say so clearly, and mark your thread as Solved:
    Forum Rules & How to Mark a thread as SOLVED

  5. #5
    Registered User
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Looking for counts from an array

    Well, that works too. Thanks Haseeb.

    I am still puzzled why the countis do not work - I just checked and I do have one that works.

    JOhn.

  6. #6
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2007
    Posts
    10,056

    Re: Looking for counts from an array

    As Haseeb says, all ranges must be the same size. This, in fact, applies to all "IF" and "IFS" functions like SUMIF, COUNTIFS, AVERAGEIFS etc......because there's always a "one-to-one" relationship between the cells, e.g. in COUNTIFS(A2:B10,"x","C2:D10,"y") you are counting instances of "paired" cells where the conditions are met, e.g. A4 is paired with C4, B9 with D9 etc. Given that setup it doesn't make sense to allow the ranges to be different sizes.....

    Note that SUMIF (and AVERAGEIF) allows you to "apparently" set ranges to different sizes, e.g.

    =SUMIF(A:C,"x",D:D)

    ....but, in fact, the sum range always becomes the same size (and shape) as the criteria range so with that formula if you have "x"s in columns B and C then the corresponding cells in columns E and F are summed......even though those columns aren't included in the formula.
    Audere est facere

  7. #7
    Registered User
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Looking for counts from an array

    I am OK with that. When the erroror return is #VALUE! does it mean I have written the function correctly?

    John.

+ 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