+ Reply to Thread
Results 1 to 8 of 8

IF function not respecting conditions....

  1. #1
    Registered User
    Join Date
    03-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2010
    Posts
    27

    IF function not respecting conditions....

    Hello everyone,

    So basically I have a sheet with a time table of Monday to Friday for daycare employees to insert their schedule. These employees do not necessarily work 7hrs a day in a block, they can work in the AM and return after noon, if there is a gap of 1.5 hrs or more they receive a split shift premium. There are two formulas of concern. The first calculates the split between shifts, based on selections from drop down lists, =IF(E17=$Y$8,0,(C18-E17)*24), this one works fine.

    The second formula looks at the results of the first and determines if there is a gap >=1.5 =IF(OR(AA16>=1.5,AA17>=1.5,AA18>=1.5),"Y","N").

    The problem is with the second formula. AA16 is equal to 1.5 (not 1.49999 etc) yet returns a "N". If I change the reference to another cell and just type 1.5 if says "Y".

    Why is the second IF function not respecting the condition? It only seems to mess up if the first one is exactly 1.5 despite the condition being >=

    If anyone has an idea on the problem it would be greatly appreciated! Thanks!

    -Dawson

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,714

    Re: IF function not respecting conditions....

    Times in Excel are stored internally as fractions of a 24-hour day, and there can be a difference between the decimal fractional values that we use and the binary representation of those fractions which computers use. These differences (often very small values) can be hidden by formatting and if you have a value like 1.499999999999 which is formatted to show 1 decimal place it will look like 1.5. One way around it is to wrap a rounding function around your cells, like this:

    =IF(OR(ROUND(AA16,1)>=1.5,ROUND(AA17,1)>=1.5,ROUND(AA18,1)>=1.5),"Y","N").

    Or you can put the ROUND functions within the cells AA16 to AA18.

    Hope this helps.

    Pete

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: IF function not respecting conditions....

    if you need a referenco of more or equal than 1.5 hours it will be safer to check if it is more than 1hr29min59.5s which seems to be crazy, but due to limited precision of floating point calculations is sometimes needed.

    so try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    etc
    Best Regards,

    Kaper

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: IF function not respecting conditions....

    PS. instead of OR if you want to compare several values against one, you can use MAX of the values to be compared, so either:
    =if(max(AA16,AA17,AA18)>=5399.5/86400,"Y","N")

    @Pete_UK: as for rounding - I'd not go for round(somehourswithdecimalpart,1), because one will get 1.5 for any time between 01:27:00 and 01:33:00
    if rounding, then even ,3) is not enough 01:29:00 rounds to 1.500 but ,4) will be fine :-)
    Last edited by Kaper; 08-13-2015 at 10:15 AM. Reason: added comment on rounding to 4 decimal digits as working fine

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,714

    Re: IF function not respecting conditions....

    Quote Originally Posted by Kaper View Post
    @Pete_UK: as for rounding - I'd not go for round(somehourswithdecimalpart,1), because one will get 1.5 for any time between 01:27:00 and 01:33:00
    if rounding, then even ,3) is not enough 01:29:00 rounds to 1.500 but ,4) will be fine :-)
    Yes, good point, Kaper. I did originally have ,2 in there, and then changed it to ,1

    Thanks,

    Pete

  6. #6
    Registered User
    Join Date
    03-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: IF function not respecting conditions....

    Your first suggestion I seemed to run into issues it worked when the drop downs showed a 1.5 hr split, but if it was less it still returned a Y. Once I tried your second one it worked perfectly. I've been doing some trial and error and it seems to be working great! Thank you very much it is very much appreciated. My coworkers think I'm an expert in Excel, I'm good, but there's always better! Thanks again!

    (This sheet was needed for a few reasons including that when filled out manually too many people would transcribe things like 1hr15m as 1.15 hrs in our payroll system instead of 1.25 lol.)

  7. #7
    Registered User
    Join Date
    03-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: IF function not respecting conditions....

    Thanks for your help! I ultimately used the =if(max(AA16,AA17,AA18)>=5399.5/86400,"Y","N") but I still appreciate the help.

  8. #8
    Registered User
    Join Date
    03-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: IF function not respecting conditions....

    very good information to know about the fractions for time and binary, without that tidbit id be going over this endlessly

+ 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. Elapsed time, respecting work hours
    By miren324 in forum Excel General
    Replies: 1
    Last Post: 03-24-2015, 05:06 PM
  2. Pivot table not respecting relationship
    By wood923 in forum Excel General
    Replies: 8
    Last Post: 11-28-2014, 02:00 PM
  3. [SOLVED] Copy up to cell is not respecting deleted/empty cells appropriately
    By Drayde in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-01-2014, 04:37 PM
  4. extract data from multiple worksheets and save to the respecting workbook
    By anitra in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2013, 05:05 AM
  5. [SOLVED] Calculating elapsed time,respecting working hours.
    By CoryX in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-10-2013, 04:13 PM
  6. Replies: 5
    Last Post: 03-08-2013, 02:16 PM
  7. Solver Not Respecting Constraints
    By Larry Curcio in forum Excel General
    Replies: 1
    Last Post: 12-29-2005, 05:50 PM

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