+ Reply to Thread
Results 1 to 12 of 12

COMPLEX Nested IF statement that uses AND, OR's and other conditions

  1. #1
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Hi,

    Here is my statement to date which returns FALSE.

    =IF(AND(ISBLANK(Q16),ISBLANK(O16),ISBLANK(S16),ISBLANK(M16)),0,IF(OR(ISBLANK(M16),ISBLANK(O16),(Q16*S16)<100),IF(OR(ISBLANK(Q16),ISBLANK(S16),(M16*O16))<100,IF((+(O16*M16)+(Q16*S16))<100,100,+(O16*M16)+(Q16*S16)))))

    I have attached the excel spreadsheet.

    Basically the answer in U6 should be this: =IF((+(O6*M6)+(Q6*S6))<100,100,+(O6*M6)+(Q6*S6)).

    BUT I now need to account for if the cells O,M,Q,S are blank or if other combinations are blank. For instance if O6 is blank OR M6 is blank it needs to then perform the calculation (Q6*S6) and if this is <100 then it must return 100, if not then it must return the answer. But it also needs to do a check on Q and S much like the way I have just described above.

    If you follow my nested if statement you should get the gist of what I'm trying to achieve. I think the problem comes in when some of the statement are true.

    Thank-you very much!!!
    Attached Files Attached Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    A very long formula . Try it.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Hi thnax for trying but it breaks if you input 0 in the cells. What I came up with was the following:

    =IF(AND(ISBLANK(Q6),ISBLANK(O6),ISBLANK(S6)),0,IF(AND(M6*O6=0,Q6*S6=0),0,IF((+(O6*M6)+(Q6*S6))<100,100,+(O6*M6)+(Q6*S6))))

    I think it covers most of the cases without breaking. If you can find a case where it breaks and fix it I would really appreciate that. Thanx!!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Maybe:

    =IF(((MAX(O6,0)*MAX(M6,0))+(Q6*S6))<100,100,(MAX(O6,0)*MAX(M6,0))+(Q6*S6))



    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    concatch, and if so:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Sorry I should have mentioned that the value must remain 0 if there is no data and not default to 100. It must only default to 100 if the calculation using columns M,O,Q,S is < 100

  7. #7
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    If I enter 1 for all the columns M,O,Q,S the result returned is 200 which is incorrect. This happens for both your formulas. So far my second formula seems to hold. Thanks though

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Why is it incorrect? 1 isn't blank, which is what you said you needed to adapt your formula to cater for.

    Regards

  9. #9
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Instead of IF() functions, try this:

    =((ISBLANK(Q16)*ISBLANK(O16)*ISBLANK(S16)*ISBLANK(M16))>0) * ((ISBLANK(M16)+ISBLANK(O16)+((Q16* S16)<100))>0) * (((ISBLANK(Q16)+ISBLANK(S16)+((M16*O16)<100))>0) * (((O16*M16)+(Q16*S16))<100)*100 + (((O16*M16)+(Q16*S16))<100)*((O16*M16 )+(Q16*S16))

    The above formula goes on the assumption that IF() functions are precious and should not be wasted. By changing your IF() tree into straight math and taking advantage of Excel's behavior of coercing TRUE/FALSE values to 1/0 when in a math equation, we can eliminate the nested IF() limit of 7, speed up calculation, and add complexity.

    See this article that explains how many uses of IF() can be adapted to other functions to get the same result, but faster and easier to read.
    Last edited by Whizbang; 10-25-2011 at 12:08 PM.

  10. #10
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Oops. Forgot to paste the link to the article.

    http://www.excelhero.com/blog/2010/01/i-heart-if.html

  11. #11
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    @TMShucks your formula works fine but the value doesn't default to 0 if there are no values inputed.
    @Whizbang, that article is very useful, I learnt a lot thank-you!

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: COMPLEX Nested IF statement that uses AND, OR's and other conditions

    Your requirement seems to be changing. You originally said:

    For instance if O6 is blank OR M6 is blank it needs to then perform the calculation (Q6*S6) and if this is <100 then it must return 100, if not then it must return the answer.
    I have to admit that I didn't pick up on the second part but the same approach could be applied.

    It won't default to zero if no values are input. That will result in a value which is less than 100 and will apply the true part of the formula which will return 100.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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