+ Reply to Thread
Results 1 to 7 of 7

IF with two ANDs and 3 answers

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,963

    IF with two ANDs and 3 answers

    I'm stuck on syntax. Here's my problem:
    Column Q contains Current Balance of Overtime Hours
    Column R contains OT earned in a specified period
    Column S contains Yes or No (whether to pay out or not)

    In column T I want this:
    IF(S="Yes") AND Q>R, answer would be R
    IF(S="Yes") AND Q<R, Answer would be Q
    IF(S="No"), Answer would be 0.

    I'm getting my head all twisted around trying to create the formula. Can anyone help?

    Thanks,
    John
    Last edited by jomili; 10-26-2010 at 12:50 PM.

  2. #2
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: IF with two ANDs and 3 answers

    Maybe these ones

    =IF(S1="Yes",IF(Q1>R1,R1,IF(Q1<R1,Q1)),0)
    or
    =IF(AND(S1="Yes",Q1>R1),R1,IF(AND(S1="Yes",Q1<R1),Q1,IF(S1="No",0)))
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,784

    Re: IF with two ANDs and 3 answers

    Quote Originally Posted by jomili View Post
    IF(S="Yes") AND Q>R, answer would be R
    IF(S="Yes") AND Q<R, Answer would be Q
    IF(S="No"), Answer would be 0.
    There are two cases that may need to be considered:

    S="Yes" AND Q=R
    S <> "Yes" AND S <> "No"

    What do you want in those cases?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: IF with two ANDs and 3 answers

    Sounds as though you want:

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,963

    Re: IF with two ANDs and 3 answers

    Wow, a lot of help in such a short time! I just got out of a meeting, so just looked at the responses.

    Contaminated,
    your first formula worked admirably for my test data. I haven't yet tried the second one.

    6StringJazzer, you bring up two very good points.
    IF S="Yes" AND Q=R, then either R or Q would be appropriate
    IF S <> "Yes" AND S <> "No" it would have to be blank, since values are restricted. So, we would want no result.

    DonkeyOte, your formula strangley excites me, because I'm not familiar with the MIN function. I haven't tried it yet, but plan to look into it. Thanks for coming from another angle.

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,963

    Re: IF with two ANDs and 3 answers

    DonkeyOte,

    You win the prize! I've taken a few minutes to look at your formula, and I understand it. It does what I asked for, and takes care of the exceptions 6StringJazzer brought up.

    If I understand it right, your formula
    Please Login or Register  to view this content.
    means

    1) IF S1 is NOT equal to "Yes" (takes care of it there's something other than Yes or NO) put a Zero.
    2) IF S1 IS equal to "Yes", put the smaller of Q1 or R1.

    Brilliant! Small, elegant, but oh so powerful! Thanks so much for showing me this!

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: IF with two ANDs and 3 answers

    Simple is best... at least that's what my wife said when she agreed to marry me.

+ 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