+ Reply to Thread
Results 1 to 9 of 9

COUNTIF Anomaly

  1. #1
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    COUNTIF Anomaly

    The formula in column D is supposed to put the dates in columns A:B in ascending order, eliminating duplicates (though there are none in this example).

    A
    B
    C
    D
    E
    1
    Begin
    End
    Ordered
    2
    09/23/2016 10:41:42
    09/23/2016 10:43:42
    09/23/2016 10:41:42
    D2: =SMALL($A$2:$B$7, COUNTIF($A$2:$B$7, "<=" & D1) + 1)
    3
    09/24/2016 08:41:57
    09/24/2016 11:41:45
    09/23/2016 10:43:42
    4
    09/24/2016 09:43:25
    09/24/2016 15:16:48
    09/24/2016 08:41:57
    5
    09/24/2016 09:48:11
    09/24/2016 11:25:32
    09/24/2016 08:41:57
    6
    09/24/2016 09:51:54
    09/24/2016 11:24:54
    09/24/2016 08:41:57
    7
    09/24/2016 11:45:00
    09/24/2016 12:54:49
    09/24/2016 08:41:57


    Why does the formula start repeating the same result in D5?

    It's the COUNTIF part that's returning the wrong result.

    Cross-posted at https://www.mrexcel.com/forum/excel-...ml#post4831646
    Last edited by shg; 05-23-2017 at 08:21 PM.
    Entia non sunt multiplicanda sine necessitate

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: COUNTIF Anomaly

    Hey shg, the problem is the specific value 9/24/2016 8:41:57 AM. Change the last digit "7" to "8" and your formula works.
    The serial equivalent (ignoring the whole number portion) is .3624652777. Some sort of rounding error, I guess. COUNTIF doesn't recognize A3=D4!
    The equivalent fraction would be 31317/86400.
    31317 is NOT a prime number. Factors{3,11,13,73}
    Last edited by leelnich; 05-24-2017 at 08:22 AM.

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: COUNTIF Anomaly

    or change it to a 6...
    "24/09/2016 8:41:57" seems to be some sort of magic time for breaking countifs.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: COUNTIF Anomaly

    Maybe this?
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B C D
    2 9/23/2016 10:41:42 9/23/2016 10:43:42 9/23/2016 10:41:42
    3 9/24/2016 8:41:57 9/24/2016 11:41:45 9/23/2016 10:43:42
    4 9/24/2016 9:43:25 9/24/2016 15:16:48 9/24/2016 8:41:57
    5 9/24/2016 9:48:11 9/24/2016 11:25:32 9/24/2016 9:48:11
    6 9/24/2016 9:51:54 9/24/2016 11:24:54 9/24/2016 9:51:54
    7 9/24/2016 11:45:00 9/24/2016 12:54:49 9/24/2016 11:24:54
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: COUNTIF Anomaly

    Al, that skips cell A4, and starts repeating further down.

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: COUNTIF Anomaly

    try rounding all your date/times to something like 8 decimal places and then rounding the formula to round to the same number of decimal places (eg in this case 8).
    maybe something like
    Please Login or Register  to view this content.
    then you should get around the odd rounding of that time.
    Last edited by scottiex; 05-23-2017 at 11:02 PM.

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: COUNTIF Anomaly

    Although COUNTIF didn't recognize them as EQUAL, the formula =(A3=D4) yields TRUE, so this array formula WORKS!:

    =SMALL($A$2:$B$7, SUM(--($A$2:$B$7<= N(D1))) + 1)

    I'm guessing this is a 32-bit / 64-bit thing where COUNTIF didn't get updated correctly. I notice everyone who's responded is using Excel 2010 or later.
    We need somebody w 32-bit version (2007 or earlier) to check this.
    Last edited by leelnich; 05-24-2017 at 08:17 AM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: COUNTIF Anomaly

    Thank you all for responding.

    The problem also goes away if I first round the numbers to the nearest second, but changing data to make formulas work is not good.

    I verified that the SMALL function does indeed return members of the input set of numbers; it doesn't alter them slightly to fool the COUNTIF function. It seems like a very strange failure mode for COUNTIF, considering that a test for "<=" is very simple.

    I ended up using leelnich's suggestion:

    =SMALL($A$2:$B$7, SUM(--($A$2:$B$7 <= N(D1))) + 1)

    Thank you all again.

  9. #9
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: COUNTIF Anomaly

    Happy to help, a very interesting find!! Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Formula anomaly
    By Mulpuzzle in forum Excel Formulas & Functions
    Replies: 30
    Last Post: 07-29-2016, 12:14 AM
  2. [SOLVED] round up/down anomaly?
    By thesurfer in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-22-2015, 04:28 PM
  3. IF function anomaly
    By BBS in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-07-2007, 11:51 AM
  4. DATEDIF anomaly?
    By cruisy in forum Excel General
    Replies: 5
    Last Post: 05-25-2007, 12:10 AM
  5. [SOLVED] Printing Anomaly
    By Otto Moehrbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2005, 11:05 AM
  6. [SOLVED] Formatting Anomaly
    By Christopher Weaver in forum Excel General
    Replies: 2
    Last Post: 05-13-2005, 06:06 PM
  7. [SOLVED] VLOOKUP Anomaly
    By Tosca in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-08-2005, 05:08 AM

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