+ Reply to Thread
Results 1 to 3 of 3

COUNTIFS - Count all values in a range that equal any value in another range.

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2012
    Location
    Dorset, England
    MS-Off Ver
    Excel 2007
    Posts
    24

    COUNTIFS - Count all values in a range that equal any value in another range.

    Morning all!

    The title basically descirbes what I'm trying to achieve - I want to count all values in a range that equal any value in another range.

    So I have a massive table of about 40,000 rows, and I'm counting certain colmumns based on multiple criteria. Here's one of the formulas im using:

    =COUNTIFS(Faults!$L$2:$L$100537,">="&$D3,Faults!$L$2:$L$100537,"<"&$D4,Faults!$A$2:$A$100537,L$3,Faults!$J$2:$J$100537,L$4,Faults!$I$2:$I$100537,DataVal!N$5:N$24)
    This formula is created dynamically with VBA depending on user input, so if possible i'd like to keep it as a 'COUNTIFS' function.

    The problem is with this last bit:

    Faults!$I$2:$I$100537,DataVal!N$5:N$24

    It only counts values equal to the first cell in the range N5:N24, and not the whole range.

    Any help would be greatly appreciated!

    Cheers,

    Adam

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: COUNTIFS - Count all values in a range that equal any value in another range.

    Try SUMPRODUCT instead

    =SUMPRODUCT(--(Faults!$L$2:$L$100537>=$D3),--(Faults!$L$2:$L$100537<$D4),--(Faults!$A$2:$A$100537=L$3),--(Faults!$J$2:$J$100537=L$4),--(ISNUMBER(MATCH($I$2:$I$100537,Dataval!$N$5:$N$24,0))))
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,698

    Re: COUNTIFS - Count all values in a range that equal any value in another range.

    Hello Adam,

    When you use a 20 cell range as a criteria value the result is a 20 element array, but you only see the first value (the sum for N5). You need SUM or SUMPRODUCT wrapped around your COUNTIFS to sum that array, I prefer SUMPRODUCT as it avoids "array entry", i.e.

    =SUMPRODUCT(COUNTIFS(Faults!$L$2:$L$100537,">="&$D3,Faults!$L$2:$L$100537,"<"&$D4,Faults!$A$2:$A$100537,L$3,Faults!$J$2:$J$100537,L$4,Faults!$I$2:$I$100537,DataVal!N$5:N$24))

    Note: this gives you the normal efficiency benefits of COUNTIFS, SUMPRODUCT is only used to sum the resulting array
    Audere est facere

+ 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