+ Reply to Thread
Results 1 to 10 of 10

IF statement error

Hybrid View

SkampDiddy IF statement error 03-24-2010, 09:35 AM
6StringJazzer Re: IF statement error 03-24-2010, 09:48 AM
SkampDiddy Re: IF statement error 03-24-2010, 09:58 AM
SkampDiddy Re: IF statement error 03-24-2010, 10:04 AM
6StringJazzer Re: IF statement error 03-24-2010, 10:04 AM
zbor Re: IF statement error 03-24-2010, 09:53 AM
mdbct Re: IF statement error 03-24-2010, 09:56 AM
contaminated Re: IF statement error 03-24-2010, 09:58 AM
mdbct Re: IF statement error 03-24-2010, 10:02 AM
zbor Re: IF statement error 03-24-2010, 10:04 AM
  1. #1
    Registered User
    Join Date
    03-24-2010
    Location
    St. John's, NL
    MS-Off Ver
    Excel 2007
    Posts
    5

    IF statement error

    Hey:

    I keep getting an error on the following statement:

    =IF((C21<500, "0%", IF(AND(C21>501, C21<700, "10%", IF(AND(C21>701, C21<900, "15%", IF(AND(C21>901, C21<1200, "20%", IF(AND(C21>1201, "20%"))))))))))

    Basically I'm trying to take a value and determine the discount based on the total. If the total is less than $500 then there is a 0% discount, If between 501 and 700 then $10%, if 701 and 900 then, 15%, if between 901 and 1200 then 20%, if greater than 1201, then 20%.

    I looked up some help online, but I cannot figure out the mistake I am making. Any help would be great, thanks!

    SkampDiddy

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,982

    Re: IF statement error

    You need to have parentheses around the arguments to the AND functions.

    =IF(C21<500, "0%", IF(AND(C21>501, C21<700), "10%", IF(AND(C21>701, C21<900), "15%", IF(AND(C21>901, C21<1200), "20%", IF(C21>1201, "20%")))))

    However, your answers are being generated as strings. Depending on what you do with them you might want numbers. For example, instead of "10%" use 0.1.

    Also, I'm going to think about this for another minute, I think this can be done more elegantly with LOOKUP.

    EDIT: You are not including the cases where C21=500,501,700,701,900,901,1200,1201. You need to rethink your comparisons.
    Last edited by 6StringJazzer; 03-24-2010 at 09:56 AM.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    03-24-2010
    Location
    St. John's, NL
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: IF statement error

    Ok I put the formula in and it works perfectly, but now I have a new problem. I should have applied the discount to the before tax amount, not the after tax amount. So I tried to change C21 to C19, but that gives me a "circular formula" (I think that is what it says). I need to be able to read the subtotal and then determine the discount. Then take that price and times it by tax (13%) to give me my total. Is this possible?

  4. #4
    Registered User
    Join Date
    03-24-2010
    Location
    St. John's, NL
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: IF statement error

    Quote Originally Posted by SkampDiddy View Post
    Ok I put the formula in and it works perfectly, but now I have a new problem. I should have applied the discount to the before tax amount, not the after tax amount. So I tried to change C21 to C19, but that gives me a "circular formula" (I think that is what it says). I need to be able to read the subtotal and then determine the discount. Then take that price and times it by tax (13%) to give me my total. Is this possible?
    Nevermind I just had to change around the order. Thanks for your help, it works great!

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,982

    Re: IF statement error

    Quote Originally Posted by SkampDiddy View Post
    ...I should have applied the discount to the before tax amount, not the after tax amount. So I tried to change C21 to C19, but that gives me a "circular formula" (I think that is what it says). I need to be able to read the subtotal and then determine the discount. Then take that price and times it by tax (13%) to give me my total. Is this possible?
    What's in C19? What cell is the base price in? How are you calculating tax? At this point attaching the workbook would be helpful.

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,054

    Re: IF statement error

    Here, try this: =LOOKUP(C21,{0,500,700,900},{0,10,15,20}/100)
    Never use Merged Cells in Excel

  7. #7
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: IF statement error

    The Lookup formula would be:
    =LOOKUP(C1,{0,501,701,901},{0,0.1,0.15,0.2})

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

    Re: IF statement error

    You forgot to close parentesis after AND function

    =IF(C5<500,"0%",IF(AND(C5>501,C5<700),"10%",IF(AND(C5>701,C5<900),"15%",IF(AND(C5>901,C5<1200),"20%",IF(C5>1201,"20%")))))

    Actua;;y u can use simple VLOOKUP See file
    Attached Files Attached Files
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  9. #9
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: IF statement error

    Since there is only one cell reference, I'm guessing you tried entering the formula in cell C19 if you are receiving the circular reference error.

    Just about anything is possible. Can you provide a sample sheet with raw data and the expected results?

  10. #10
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,054

    Re: IF statement error

    Also, according to your IF function:

    =IF(C21<500, "0%", IF(AND(C21>501, C21<700), etc...

    What if is C21=500.8 or exactly 500?

    Is it less than 500? No. So IF function go further.
    Is ti bigger than 501 and less than 700? No... So IF function go further (up to the end.

    And you get result 20% (I doubt it's correct result).

    And all of that you can avoid by proper using of IF function.

    Look at this way:

    =IF(C21<500, 0, 10)

    Now.. if number is 500.8 it will return 10.
    Is it less than 500? No. Then ELSE -> 10

    So your correct formula would be:

    =IF((C21<500, "0%", IF(C21<700, "10%", IF( C21<900, "15%", "20%"))))

    No need to test is it bigger than 500 because you already check it: Is it less than 500? No. Then what is it? (If your answer is greater then you got the point )

+ 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