We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
The Forum now has a brand new text editor, adding a bunch of handy features to use when creating posts. Read more in our how-to guide

EXCEL -IF,THEN etc help ?

Hi all, i am getting confused by nested IF statements..

I have a value that appears in E34 which varies as a result of other calculations

I want to compare that result in E34 and output a result in B37 based on the following..

E34

<=0.5 B37=2
>0.5 AND <=0.8 B37=3
>0.8 AND <=1 B37=4


I think this can be done with a nested IF statement but im not sure if there is a formula template to help with complex IFs ?

Thanks
Feudal Britain needs land reform. 70% of the land is "owned" by 1 % of the population and at least 50% is unregistered (inherited by landed gentry). Thats why your slave box costs so much..

Comments

  • [Deleted User]
    [Deleted User] Posts: 0 Newbie
    Holiday Haggler
    edited 25 November 2016 at 7:53PM
    =IF(E34<=0.5,2,IF(AND(E34>0.5, E34<=0.8),3,IF(AND(E34>0.8, E34<=1),4)))

    There you go. In each nested IF statement, you put the value you want outputted into the 'true' section, and in the 'false' section you put the next IF statement

    e.g. If you need to account for values over 1...

    =IF(E34<=0.5,2,IF(AND(E34>0.5, E34<=0.8),3,IF(AND(E34>0.8, E34<=1),4,IF(E34>1, 5)))

    Split the clauses out, make sure they work, then chain them together
  • C_Mababejive
    C_Mababejive Posts: 11,668 Forumite
    Part of the Furniture 10,000 Posts Name Dropper Combo Breaker
    Thanks for the quick reply Ringo,, have been searching on line tutorials and just got blinded by it all ! I shall use your reply to understand how it works :)
    Feudal Britain needs land reform. 70% of the land is "owned" by 1 % of the population and at least 50% is unregistered (inherited by landed gentry). Thats why your slave box costs so much..
  • [Deleted User]
    [Deleted User] Posts: 0 Newbie
    Holiday Haggler
    edited 25 November 2016 at 8:15PM
    If it helps, here are the three separate IFs

    =IF($A$1<=0.5,2,)
    =IF(AND($A$1>0.5, $A$1<=0.8),3)
    =IF(AND($A$1>0.8, $A$1<=1),4)

    Here's the chain..

    =IF(E34<=0.5,2,IF(AND(E34>0.5, E34<=0.8),3,IF(AND(E34>0.8, E34<=1),4)))

    You could always form that as...

    =IF(E34<=0.5, 2,
    IF(AND(E34>0.5, E34<=0.8), 3,
    IF(AND(E34>0.8, E34<=1), 4)
    )
    )


    If you need help making sure there's the right number of brackets, try getting a programmers editor like notepad++
  • You can do a shorter version without the ANDs:
    =IF(E34<=0.5,2,IF(E34<=0.8,3,IF(E34<=1,4)))
    

    The second IF statement is only reached if E34 is greater than 0.5, so any test for E34>0.5 at that point is tautological.
  • thescouselander
    thescouselander Posts: 5,547 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Combo Breaker
    edited 26 November 2016 at 8:14AM
    Nested if statements are the devil's work. Better to use a case statement as part of a user defined function action IMO.

    Alternatively, if you have the latest version of excel, you could use the IFS function.
  • Heedtheadvice
    Heedtheadvice Posts: 2,947 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    edited 26 November 2016 at 10:48AM
    You just beat me to that scouse!
    Nested formulas are not the easiest of thing to work with and even worserer to understand when you come back to them later to try and audit or fault find on them. By no means impossible but better to make life easy in the first place!
    1 use meaningfull cell (or range names) /in the example we could hold the desired test value in cells 0, 0.5 and 1 and name them as low limit, middle value and high limit (or something similar)
    2 the function does not need to be nested but can be held in (in this case) three separate cells
    3 if using excel 2007 onwards each bit of the nested if function can be defined separately (using defined name, and the definition is a function!) and then combined in the 'answer cell'

    For the latter consider
    :
    =IF(OneToSix,OneToSix,SevenToThirteen) a simple if statement held in the cell with the same logic (test,true answer,false answer)
    (Obviously for different values to OP question but very understandable!) Great explanation at c.pearson.com/excel/nested.htm

    Not only does separation (rather than lots of nesting) make it easier to understand each part can be separately proven and tested against unexpected results - consider Ringo's addition of '5' in the last of the nested ifs. That copes with a perhaps unexpected value to test and 5 could easily be replaced with "oops" or "out of test range" etc. Equally what would be the result of the nested IF statements if the cell contained an error code or was simply blank? ....just food for thought......
  • C_Mababejive
    C_Mababejive Posts: 11,668 Forumite
    Part of the Furniture 10,000 Posts Name Dropper Combo Breaker
    What we occasional users really need is a simple on line/ or software tool to automate it having the ability to put various logical operators in it ..
    Feudal Britain needs land reform. 70% of the land is "owned" by 1 % of the population and at least 50% is unregistered (inherited by landed gentry). Thats why your slave box costs so much..
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 353.5K Banking & Borrowing
  • 254.1K Reduce Debt & Boost Income
  • 455K Spending & Discounts
  • 246.6K Work, Benefits & Business
  • 602.9K Mortgages, Homes & Bills
  • 178.1K Life & Family
  • 260.6K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.