+ Reply to Thread
Results 1 to 4 of 4

Formula not calculating all variables correctly

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Formula not calculating all variables correctly

    Following formula should calculate how many shift hours are "premium":

    =IF(AND(OR(ISNUMBER(SEARCH("AM*",A17)),ISNUMBER(SEARCH("DOUBLE*",A17)),B17 < TIME(8,0,0))),TIME(8,45,0)-B17)+IF(AND(ISNUMBER(SEARCH("AM*",A17)),C17>TIME(14,15,0)),C17-TIME(14,15,0))+IF(AND(ISNUMBER(SEARCH("PM*",A17)),B17 < TIME(12,45,0)),C17-TIME(12,45,0))+IF(AND(OR(ISNUMBER(SEARCH("DOUBLE*",A17)),ISNUMBER(SEARCH("PM*",A17)),C17 > TIME(17,30,0))),C17-TIME(17,30,0))

    Should work as follows:

    1. AM or Double Shift starts
    If employee starts before 08:00, Start time until 08:45 is "Premium"
    If employee starts on or after 08:00, then no Premium hours

    2.AM shift ends
    If employee finishes later than 14:15, then 14:15 to Finish time are "Premium"

    3. PM Shift Starts
    If employee starts before 12:45, Start time until 12:45 is "Premium"

    3. PM or Double Shifts end
    If employee finishes later than 17:30, then 17:30 to Finish time are "Premium"

    Unfortunately, as shown on the attachment, some combinations are generating wrong answers:

    AM Shift 08:00 - 14:15 = 00:45 S/be no premium - started at 08:00
    AM Shift 09:00 - 15:00 = 00:30 S/be Premium 14:15 - 15:00

    Double 07:00 - 16:00 = 00:15 S/be Premium 07:00 - 08:45
    Double 08:00 - 17:30 = 00:45 S/be no premium - started at 08:00, finished 17:30
    Double 09:00 - 19:00 = 01:15 S/be Premium 17:30 - 19:00

    Hopefully someone can see the flaw? All suggestions, pointers and solutions accepted grqatefully.

    Ochimus
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,223

    Re: Formula not calculating all variables correctly

    Try

    =IF(AND(OR(ISNUMBER(SEARCH("AM*",A16)),ISNUMBER(SEARCH("DOUBLE*",A16))),B16 < TIME(8,0,0)),TIME(8,45,0)-B16,0)+IF(AND(ISNUMBER(SEARCH("AM*",A16)),C16>TIME(14,15,0)),C16-TIME(14,15,0),0)+IF(AND(ISNUMBER(SEARCH("PM*",A16)),B16 < TIME(12,45,0)),TIME(12,45,0)-B16)+IF(AND(OR(ISNUMBER(SEARCH("DOUBLE*",A16)),ISNUMBER(SEARCH("PM*",A16))),C16 > TIME(17,30,0)),C16-TIME(17,30,0),0)

  3. #3
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Formula not calculating all variables correctly

    John,

    Many thanks for prompt response, which works perfectly,

    I'll leave it until the morning to compare them and see where I missed something

    Ochimus

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,223

    Re: Formula not calculating all variables correctly

    Differences ....(your formula below)

    Extra brackets and wrong calculation ..

    =IF(AND(OR(ISNUMBER(SEARCH("AM*",A17)),ISNUMBER(SEARCH("DOUBLE*",A17)),B17 < TIME(8,0,0))),TIME(8,45,0)-B17)+IF(AND(ISNUMBER(SEARCH("AM*",A17)),C17>TIME(14,15,0)),C17-TIME(14,15,0))+IF(AND(ISNUMBER(SEARCH("PM*",A17)),B17 < TIME(12,45,0)),C17-TIME(12,45,0))+IF(AND(OR(ISNUMBER(SEARCH("DOUBLE*",A17)),ISNUMBER(SEARCH("PM*",A17)),C17 > TIME(17,30,0))),C17-TIME(17,30,0))

+ 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. Formula not calculating correctly?
    By Dooberry in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-20-2015, 06:38 AM
  2. [SOLVED] Formula not calculating correctly
    By ratboyab in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 06-29-2013, 06:35 PM
  3. Formula not calculating correctly
    By mgfuentes in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-09-2012, 01:21 PM
  4. Formula not calculating correctly
    By Whittle82 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2012, 05:54 PM
  5. Excel Not Calculating Formula Correctly
    By Njisom13 in forum Excel General
    Replies: 2
    Last Post: 12-27-2010, 07:38 AM
  6. Formula Not Calculating Correctly
    By be965 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-23-2007, 03:30 PM
  7. Simple formula not calculating correctly
    By LeighG in forum Excel General
    Replies: 1
    Last Post: 01-26-2005, 11:22 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