+ Reply to Thread
Results 1 to 25 of 25

Unable to use Nested IF formula

  1. #1
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Unable to use Nested IF formula

    Hi Guys,

    I have a pretty tough problem which I need some help on.
    Been trying to get this to work but tried using normal IF formula but can't get it to work.


    I have an Excel file as attached which I would need to have a formula as below if possible:

    1) If C1=4 then if value in A1>8 hours then B1 should show value as N else if A1<8 hours then B1 should show as Y

    2) If C1=3 then if value in A1>4 hours then B1 should show value as N else if A1<4 hours then B1 should show as Y

    3) If C1=2 then if value in A1>2 hours then B1 should show value as N else if A1<2 hours then B1 should show as Y

    4) If C1=1 then if value in A1>1 hours then B1 should show value as N else if A1<1 hours then B1 should show as Y


    In short, I am trying to combine all the IF and Else statement to make it into 1 long formula.

    The value of C1 will be depending on certain criteria as below:

    4 = 8 hours
    3 = 4 hours
    2 = 2 hours
    1 = 1 hour


    Attach is the sample of the file which I need the data from. Hopefully someone here can help me out guys.

    Book2.xlsx

    Regards,
    Mark

  2. #2
    Registered User
    Join Date
    01-23-2014
    Location
    Romania
    MS-Off Ver
    Excel 2016
    Posts
    54

    Re: Unable to use Nested IF formula

    Hello Mark,

    i'm not sure it's the best solution, but try this:

    =IF(C1=4,IF(VALUE(MID(A1,3,2))>8,"N","Y"),IF(C1=3,IF(VALUE(MID(A1,3,2))>4,"N","Y"),IF(C1=2,IF(VALUE(MID(A1,3,2))>2,"N","Y"),IF(C1=1,IF(VALUE(MID(A1,3,2))>1,"N","Y")))))

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Unable to use Nested IF formula

    Hi,

    One way

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


    You could simplify that somewhat if your column A cells contained a more 'normal' Time value.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by tchock View Post
    Hello Mark,

    i'm not sure it's the best solution, but try this:

    =IF(C1=4,IF(VALUE(MID(A1,3,2))>8,"N","Y"),IF(C1=3,IF(VALUE(MID(A1,3,2))>4,"N","Y"),IF(C1=2,IF(VALUE(MID(A1,3,2))>2,"N","Y"),IF(C1=1,IF(VALUE(MID(A1,3,2))>1,"N","Y")))))
    Hi tchock,

    Tried your suggestion but when it does not work. When I changed the value to more than 4 hours in column A3, it still shows result as Y.

  5. #5
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    One way

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



    You could simplify that somewhat if your column A cells contained a more 'normal' Time value.
    Hi Richard,


    Tried your formula as well but it does not show the correct value. Maybe it's the time problem? I can't manipulate the time because it's pulled from a tool and I have about 2500 records to check.

  6. #6
    Registered User
    Join Date
    01-23-2014
    Location
    Romania
    MS-Off Ver
    Excel 2016
    Posts
    54

    Re: Unable to use Nested IF formula

    Quote Originally Posted by mark888 View Post
    Hi tchock,

    Tried your suggestion but when it does not work. When I changed the value to more than 4 hours in column A3, it still shows result as Y.
    Maybe your conditions should have been ">=" instead of ">"? For example:
    If C1=4 then if value in A1>=8 hours then B1 should show value as N else if A1<8 hours then B1 should show as Y

    In this case, you just have to add the "=" in your formula:
    =IF(C1=4,IF(VALUE(MID(A1,3,2))>=8,"N","Y"),IF(C1=3,IF(VALUE(MID(A1,3,2))>=4,"N","Y"),IF(C1=2,IF(VALUE(MID(A1,3,2))>=2,"N","Y"),IF(C1=1,IF(VALUE(MID(A1,3,2))>=1,"N","Y")))))

  7. #7
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Unable to use Nested IF formula

    =IF(LEFT(A1,FIND(" ",A1)-1)+RIGHT(A1,8)>CHOOSE(C1,1/24,2/24,4/24,8/24),"N","Y")
    Try this in B1 and copy towards down
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  8. #8
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by tchock View Post
    Maybe your conditions should have been ">=" instead of ">"? For example:
    If C1=4 then if value in A1>=8 hours then B1 should show value as N else if A1<8 hours then B1 should show as Y

    In this case, you just have to add the "=" in your formula:
    =IF(C1=4,IF(VALUE(MID(A1,3,2))>=8,"N","Y"),IF(C1=3,IF(VALUE(MID(A1,3,2))>=4,"N","Y"),IF(C1=2,IF(VALUE(MID(A1,3,2))>=2,"N","Y"),IF(C1=1,IF(VALUE(MID(A1,3,2))>=1,"N","Y")))))
    Hi again tchock,

    Yes you are right. That worked well but when I inserted days in cell A1 before the time as 2 14:17:43, it shows me N when it should be Y. Any ideas on how to fix this?

    Kind Regards,
    Mark.

  9. #9
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by nflsales View Post
    =IF(LEFT(A1,FIND(" ",A1)-1)+RIGHT(A1,8)>CHOOSE(C1,1/24,2/24,4/24,8/24),"N","Y")
    Try this in B1 and copy towards down
    Hi Siva,

    Tried it but it did not work as well for the days in front of the time.

    Kind Regards,
    Mark.

  10. #10
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Unable to use Nested IF formula

    =IF(--RIGHT(A1,8)>CHOOSE(C1,1/24,2/24,4/24,8/24),"N","Y")
    Try this

  11. #11
    Registered User
    Join Date
    01-23-2014
    Location
    Romania
    MS-Off Ver
    Excel 2016
    Posts
    54

    Re: Unable to use Nested IF formula

    Hi Mark,

    I'm not sure I understand why you should have "Y" instead of "N"...it seems to me that, based on your conditions and unless you want to add an additional one, the correct result for 2 14:17:43 should still be "N".

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Unable to use Nested IF formula

    Quote Originally Posted by mark888 View Post
    Hi Richard,


    Tried your formula as well but it does not show the correct value. Maybe it's the time problem? I can't manipulate the time because it's pulled from a tool and I have about 2500 records to check.
    Hi,

    It returns the same values that you show in column B. See attached.

    Can yo explain further what the problem is?
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by nflsales View Post
    =IF(--RIGHT(A1,8)>CHOOSE(C1,1/24,2/24,4/24,8/24),"N","Y")
    Try this
    Hi Nflsales,

    Tried your formula and it still works for the time formula but if days are involved it still shows as Y instead of N. Not sure if there is anything can be done to fix this?

    Kind Regards,
    Mark.

  14. #14
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    It returns the same values that you show in column B. See attached.

    Can yo explain further what the problem is?
    Hi Richard,

    Sorry my mistake I did not make it clear.
    The problem is because the format is in dd hh:mm:ss so the formula for the time works well but if I insert days in front, it returns the value of Y when it should be N.

    Kind Regards,
    Mark.

  15. #15
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by tchock View Post
    Hi Mark,

    I'm not sure I understand why you should have "Y" instead of "N"...it seems to me that, based on your conditions and unless you want to add an additional one, the correct result for 2 14:17:43 should still be "N".
    Hi Tchock,

    Sorry my mistake it was a typo on my side. When I inserted days in cell A1 before the time as 2 14:17:43, it shows me Y when it should be N.

    Kind Regards,
    Mark.

  16. #16
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Unable to use Nested IF formula

    Try

    =IF(REPLACE(A1,1,FIND(" ",A1),"")+0>TIME(C1,0,0),"N","Y")

    EFMark888.xlsx

  17. #17
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Unable to use Nested IF formula

    Wait, that just used straight hours based on Value in C of 1 2 3 and 4...
    To do 1 2 4 and 8 hours based on value of C being 1 2 3 and 4 it would be

    =IF(REPLACE(A1,1,FIND(" ",A1),"")+0>TIME(CHOOSE(C1,1,2,4,8),0,0),"N","Y")

  18. #18
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by Jonmo1 View Post
    Wait, that just used straight hours based on Value in C of 1 2 3 and 4...
    To do 1 2 4 and 8 hours based on value of C being 1 2 3 and 4 it would be

    =IF(REPLACE(A1,1,FIND(" ",A1),"")+0>TIME(CHOOSE(C1,1,2,4,8),0,0),"N","Y")
    Hi Jonmo,

    Tried the formula and it works for the time perfectly but when I changed the days from 00 to more than 1 day(01,10), it still shows as Y when it should be N. Is there any fix so that it calculates the days in front as well?

    Kind Regards,
    Mark.

  19. #19
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Unable to use Nested IF formula

    Try
    =IF(REPLACE(A1,1,FIND(" ",A1),"")+LEFT(A1,FIND(" ",A1))>TIME(CHOOSE(C1,1,2,4,8),0,0),"N","Y")

  20. #20
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by Jonmo1 View Post
    Try
    =IF(REPLACE(A1,1,FIND(" ",A1),"")+LEFT(A1,FIND(" ",A1))>TIME(CHOOSE(C1,1,2,4,8),0,0),"N","Y")
    Hi Jonmo1,

    Tested it and it works perfectly now. Thats just pure genius ..I don't think I could ever had solved that. Thank you very much to you and all of the rest who had tried to help out. You guys are the best!!!

    Kind Regards,
    Mark.

  21. #21
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Unable to use Nested IF formula

    Quote Originally Posted by mark888 View Post
    Hi Richard,

    Sorry my mistake I did not make it clear.
    The problem is because the format is in dd hh:mm:ss so the formula for the time works well but if I insert days in front, it returns the value of Y when it should be N.

    Kind Regards,
    Mark.
    Hi,

    Can you clarify what you mean by 'insert days in front'. Does the current 0 mean zero days? Of course the formula as given will still work whilst the number of days is a single digit. If you have more than 9 days then as stated it will not work. But since the formula is a simple string slicing formula just increment the start point of the MID bits of the formula. The foolproof way to do it would be to find the position of the first space character and build that into the formula as the starting point for the MID functions.

  22. #22
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Unable to use Nested IF formula

    You're welcome.

  23. #23
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Can you clarify what you mean by 'insert days in front'. Does the current 0 mean zero days? Of course the formula as given will still work whilst the number of days is a single digit. If you have more than 9 days then as stated it will not work. But since the formula is a simple string slicing formula just increment the start point of the MID bits of the formula. The foolproof way to do it would be to find the position of the first space character and build that into the formula as the starting point for the MID functions.
    Hi Richard,

    Yes the current 0 in front is meant as zero days. Sorry for confusing you.
    On the bright side, Jonmo1 has came up with the solution. Thanks for all your help Richard

    Kind Regards,
    Mark.

  24. #24
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Unable to use Nested IF formula

    Quote Originally Posted by mark888 View Post
    Hi Siva,

    Tried it but it did not work as well for the days in front of the time.

    Kind Regards,
    Mark.
    =IF(REPLACE(A1,1,FIND(" ",A1),"")+LEFT(A1,FIND(" ",A1))>TIME(CHOOSE(C1,1,2,4,8),0,0),"N","Y")
    and =IF(LEFT(A1,FIND(" ",A1)-1)+RIGHT(A1,8)>CHOOSE(C1,1/24,2/24,4/24,8/24),"N","Y") [Post 7]
    booth are giving the same result
    i did not find any difference in the end result of the above formula
    Last edited by samba_ravi; 01-06-2015 at 11:11 AM.

  25. #25
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to use Nested IF formula

    Quote Originally Posted by nflsales View Post
    =IF(REPLACE(A1,1,FIND(" ",A1),"")+LEFT(A1,FIND(" ",A1))>TIME(CHOOSE(C1,1,2,4,8),0,0),"N","Y")
    and =IF(LEFT(A1,FIND(" ",A1)-1)+RIGHT(A1,8)>CHOOSE(C1,1/24,2/24,4/24,8/24),"N","Y") [Post 7]
    booth are giving the same result
    i did not find any difference in the end result of the above formula
    Hi Siva,

    Good morning and sorry for the late reply as it was almost close to midnight yesterday. Yes I have tried your formula and it is working exactly the same as Jonmo1's formula. I'm not sure how come when I tried it last night it wasnt working. I must have definitely copied the wrong formula from you. Apologies for that.

    Kind Regards,
    Mark.

+ 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. Unable to Paste into Formula Bar
    By Motox in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-05-2013, 09:39 PM
  2. [SOLVED] IF formula- UNABLE TO CREATE CORRECT FORMULA
    By SHEFFCOURT in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 03-04-2013, 02:31 PM
  3. Replies: 3
    Last Post: 11-08-2012, 07:25 PM
  4. Unable to enter formula
    By walrasianxl in forum Excel General
    Replies: 1
    Last Post: 09-21-2010, 03:18 PM
  5. help on a nested countif/nested if formula
    By vickiemc in forum Excel General
    Replies: 2
    Last Post: 08-13-2008, 08:29 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