/

IF, Nested IF, AND, OR Criteria in LibreOffice Calc

827 views
15

In this tutorial, you would learn the basics of powerful IF, nested IF, AND, OR conditions in LibreOffice Calc.

Summary

The IF Function is a logical test at your cell which returns TRUE when a condition is met; otherwise returns FALSE. Hence you can use it to return any different value in the target cell based on your test. You can also extend your test using nested-IF condition clubbed with AND, OR operators.

Purpose

Logical test for a condition in any given cell.

Return Value

Returns your values based on TRUE or FALSE. If your return value is omitted, returns the string “TRUE”/”FALSE”.

Syntax

=IF(Test, value_when_true,value_when_false)

Examples

In the example below, when the temperature crosses 40 degrees C, return Hot in the corresponding cell otherwise return Normal.

=IF(A2>40,"Hot","Normal")
Simple IF Example
Simple IF Example

The above example depicts a simple IF condition. Let’s see how you can do nested IF with AND condition.

SEE ALSO:  LibreOffice Calc - Supported File Formats

To make it more complex, let’s add more conditions. When the temperature is below 15 deg C it is Cold; when between 15 and 45 deg C – Normal; Otherwise return Hot in the corresponding cell.

=IF(A2<15,"Cold",IF(AND(A2>=15,A2<45),"Normal","Hot"))
Nested IF Example
Nested IF Example

The above example contains two IF statements with a nested IF. The FALSE condition of the outer IF contains another IF statement. I.g. when the first condition is False, we check another IF for further condition.

The AND function returns TRUE when both the condition is true.

Usage Notes

  • Maximum number of levels in nestes IF is 42. (via this).

So, this is how you can use the IF function in Calc. Drop a note below if you have any questions.


Looking for something else?

Read our complete tutorial index of Calc, Writer, Impress and Draw.


Join our Telegram channel and stay informed on the move.

Related


arindam

IT professional by profession and founder of libreofficehelp.com. Loving Linux and other technologies since 2002. I believe in open source and its philosophy. Follow me on Twitter or email me.

15 Comments

  1. Hello all, being an old bloke I tend to forget things. I am trying to put a line graph in libre calc. I am recording daily temperatures (min. & max.) and each month I get the average temperature for the month. After a year, I wish to set a line graph with the average temps. on the Y axis then set the year on the X axis. This, of course goes over many years and I wish to set the years on the X axis. I can set the Y axis successfully, but I just cannot work out haw to get the years on the X axis. Hope someone might have a detailed clue to do this.

    • Include a row with the year as column headers and set the chart characteristics to include the first row as headers try 2017 Jan, 2017 Feb, 2017 Mar…….. or 2017 Jan, Feb, Mar…..Dec, 2018 Jan……
      Set the data as Rows. and the Y axis to AUTO. Libre will then scale the y Axis to suit the temperature range.

  2. The AND() Function in this example is superfluous. If the first IF() -15 the TRUE condition is executed and the function exits. Then it’s only necessary to test for one of the remaining conditions with another IF() with the appropriate TRUE or FALSE response.
    IF(<15,"Cold",If(<45,"Normal","Hot")

  3. How about using different functions in the same statement such as IF & AND & OR? I am having a problem resolving this statement:
    If A1 is greater than 0 and A1 is less than 250, or B1 is greater than 0 and B1 is less than 250, then 25, else 0.
    Either A1 or B1 must be between 1 and 250 in order to return a value of 25.
    Also, if either A1 or B1 is blank, 0, or greater than 250 then the result must be 0.
    Please help!
    Thanks!

      • Thank you, but not quite. I already have this solution. There also needs to have an OR function present. I need to compare A1 OR B1 with a result in C1. If A1 is greater than 0 and A1 is less than 250, or B1 is greater than 0 and B1 is less than 250, then 25, else 0 (C1).
        A B C
        Shipping units Receiving units Bonus
        1 251 0 $0.00
        2 0 249 $25.00
        3 251 249 $25.00
        4 251 251 $0.00
        5 249 249 $25.00
        A maximum of $25 bonus is given in any scenario. In this example, on day 1, greater than 250 units were shipped and no units were received, therefore no bonus. However on day 5 less than 250 units were shipped and less than 250 units received therefore a max bonus of $25. A single $25 bonus can only be given even if both shipped and received are less than 250.
        I hope this clarifies it a bit more.
        Sorry, my macro skills are horrible! 🙂
        Thanks again!

  4. I want to nest a isblank with an If statement

    If A2 is equal to T(check to see if B2 is blank, if it is return C2, if not return B2.) otherwise ” ” nothing.
    IfA2=T,IF(isblank(B2),C2,B2),” “)
    this is the best I could come up with but it’s not working.

    Any help would be greatly appreciated.

    • Its worked for me.

      =IF(A2=”T”,IF(ISBLANK(B2),C2,B2))

      Make sure you put T in the quotation in the IF condition. Also make sure your B2 doesn’t contain spaces.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.