+ Reply to Thread
Results 1 to 10 of 10

COUNTIF array function not working

  1. #1
    Registered User
    Join Date
    03-21-2013
    Location
    Nairobi, Kenya
    MS-Off Ver
    Excel 2007
    Posts
    5

    COUNTIF array function not working

    Hi,

    I apologise if this was discussed in a previous thread.

    I'm currently facilitating an Excel course and while covering array functions I noticed that my COUNTIF function wasn't giving the correct solution for the following data set:

    2,980 793
    838 756
    690 766
    865 843
    726 480
    939 643
    559 440
    678 761
    438 746
    3,838 633
    1,580 745
    1,229 687
    1,224 742
    367 753
    1,126 607
    970 1,047
    3,014 745

    The formula I used is:
    {=COUNTIF(A2:A18,"<"&B2:B18)}
    Which output "6", where the answer should be "5".

    I also used SUM(IF()) which gave me the right answer.
    {=SUM(IF(A2:A18<B2:B18,1,0))}

    I suspect the problem may have to do with duplicates or something peculiar about this particular data set. I promised to find out the root of the problem to the course participants. Can anyone help me with an explanation or tell me what I'm doing wrong?

  2. #2
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: COUNTIF array function not working

    Hrrm..did same to me, including the sum if...sumproduct returned the right number as well..

    I do have 1 question, why are you array entering the countif...you get the same number without it (still WRONG, but the same result ) ?
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  3. #3
    Registered User
    Join Date
    03-21-2013
    Location
    Nairobi, Kenya
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: COUNTIF array function not working

    Quote Originally Posted by dredwolf View Post
    Hrrm..did same to me, including the sum if...sumproduct returned the right number as well..

    I do have 1 question, why are you array entering the countif...you get the same number without it (still WRONG, but the same result ) ?
    The countif function won't work on the two columns unless its input as an array function.

  4. #4
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: COUNTIF array function not working

    it worked for me:
    =COUNTIF(A2:A18,"<"&B2:B18) (regular formula)

    returned 6, but it's STILL wrong, whether it calculates or not, the answer should be 5 not 6, so there is something not working right in either case...

  5. #5
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: COUNTIF array function not working

    Hi

    6 is correct, this is the array the COUNTIF returns: {6;6;6;7;2;3;2;6;6;3;6;4;6;6;3;10;6}
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  6. #6
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: COUNTIF array function not working

    the only problem with that Kevin is that there are only 5 values in column A that are less than the column B values... rows 3,8,9,14,16.. so where does the 6TH < come from? Sumproduct and array entered sum(if(.. both produce the proper result, so why does COUNTIF give 1 extra?

  7. #7
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: COUNTIF array function not working

    The countif: how many values in column A are less then 793=6, 756 = 6 etc, etc Array = {6;6;6;7;2;3;2;6;6;3;6;4;6;6;3;10;6} =6. Which answers the original question "COUNTIF array function not working" The countif is correct!
    Last edited by Kevin UK; 03-21-2013 at 06:55 AM.

  8. #8
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: COUNTIF array function not working

    I guess that is why sumproduct formula returns the right value, it is comparing cells to cells, not to what the countif is doing...TY for the heads up Kevin !

  9. #9
    Forum Contributor
    Join Date
    12-23-2003
    Posts
    179

    Re: COUNTIF array function not working

    6 that the CountIf formula cell shows does not answer OP's question since OP qualifies the result from the Sum array formula as correct. Rather, the CountIf formula calculates how many cells in the A range is smaller ( < ) than each value in the B range, which results in an array whose size is equal to that the criteria range. Since the result is an array, the formula cell displays the first item of the result array (it cannot do otherwise). Hence 6.

  10. #10
    Registered User
    Join Date
    03-21-2013
    Location
    Nairobi, Kenya
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: COUNTIF array function not working

    Thanks all!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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