+ Reply to Thread
Results 1 to 13 of 13

nested countif function

  1. #1
    Registered User
    Join Date
    02-24-2007
    Posts
    84

    Smile nested countif function

    I have an array of data:

    dates in column A, reults for each position on test piece in coulumns d to AI

    array covers rows 4 to 26

    Currently I use a counif function to find all the zeros in the array:
    =COUNTIF($D$20:$AI$26,0)

    Now I'd like to be able to select the rows that are counted from on the basis of date. I have tried to use the Month and Max functions to select the last month from column A, but am failing to combine it with the Counif function properly:
    =countif(and(month(MAX(A:A))),(a4:ai26,0))

    Any ideas?

    Thanks

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Countif only works with 1 criteria...you need to use Sumproduct() or if you have 2007, Countifs()...

    I don't have 2007, so here is the Sumproduct solution....

    =SUMPRODUCT((MONTH(A20:A26)=MAX(MONTH(A20:A26)))*(D20:AI26=0))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    02-24-2007
    Posts
    84

    Thumbs up

    Thanks for that.

    I'll give it a go.

    Gavin.

  4. #4
    Registered User
    Join Date
    02-24-2007
    Posts
    84

    Smile

    Unfortunately that doesn't appear to work.

    I know from doing it manually there are 26 zeros to be counted, but I'm getting a result of 90.

    Just to clarify, there dates are in column A.
    Data is in a block from D4 to AI26.

    Gavin.

  5. #5
    Registered User
    Join Date
    06-11-2007
    Location
    Nonthaburee Province, Thailand
    MS-Off Ver
    MS Office 2003 to MS Office 2010
    Posts
    82
    Please Attach the sample file contain data and the result that you want.

    Sample data not to much and easily understand when grasp within 2 minutes.
    N. Yauvasuta
    Power User Excel.

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Which dates are you trying to count, only the latest? In which case

    =SUMPRODUCT((A4:A26=MAX(A4:A26))*( D4:AI26=0)*(D4:AI26<>""))

    or any date in the latest month?

    =SUMPRODUCT((A4:A26-DAY(A4:A26)=MAX(A4:A26)-DAY(MAX(A4:A26)))*( D4:AI26=0)*(D4:AI26<>""))

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by gavster
    Unfortunately that doesn't appear to work.

    I know from doing it manually there are 26 zeros to be counted, but I'm getting a result of 90.

    Just to clarify, there dates are in column A.
    Data is in a block from D4 to AI26.

    Gavin.
    A couple of things...

    I messed up the order of Max and Month in the formula...should be reversed and also, as daddylonglegs formula suggests, the formula counts the blanks too, so to avoid any blanks, add another argument....

    Try:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-24-2007
    Posts
    84
    Sorry for not replying. Been a hectic weekend, and did'nt have a copy of the problem at home.

    Any way, tried the new code and it works a treat.

    Thanks very much.

    Gavin.

  9. #9
    Registered User
    Join Date
    02-24-2007
    Posts
    84
    Following on from this, I'm now trying to automate my monthly graph produc tion.

    In the final column (AJ) of data are the number of passes at original test,
    I'd now like to toatal these but again only for the last month.

    Any ideas?

    Gavin.

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by gavster
    Following on from this, I'm now trying to automate my monthly graph produc tion.

    In the final column (AJ) of data are the number of passes at original test,
    I'd now like to toatal these but again only for the last month.

    Any ideas?

    Gavin.
    something like...

    Please Login or Register  to view this content.
    where column AJ contains the word "Pass" if it is a pass.... change to reflect the actual string you're looking to count.

  11. #11
    Registered User
    Join Date
    02-24-2007
    Posts
    84
    Sorry, I didn't word (or type) that very well!

    The last column (AJ) has a series of numbers in it, eg 31,30,31,29,32 etc...
    each one relevant to a specific date.

    By adapting the previous code you graciously supplied, I can count the number of entries, but I actually want the SUM of these figures.

    Gavin.

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by gavster
    Sorry, I didn't word (or type) that very well!

    The last column (AJ) has a series of numbers in it, eg 31,30,31,29,32 etc...
    each one relevant to a specific date.

    By adapting the previous code you graciously supplied, I can count the number of entries, but I actually want the SUM of these figures.

    Gavin.
    Oh! I think I understand now....

    try:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-24-2007
    Posts
    84
    Thanks for that, a few alterations to get exactly what I wanted by I'm finally there.

    For those interested:

    =SUMPRODUCT((MONTH(A4:A26)=MONTH(MAX(A4:A26)))*(AJ4:AJ26<>"")*(AJ4:AJ26))

    Thanks.
    Gavin.

+ 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