Information Technology Topic
The IF Function
- Read notes
- Flashcards
- Quiz
- Confident
Study focus - 3 things
- IF has three parts: a condition that is TRUE or FALSE, the result to show when it is TRUE, and the result to show when it is FALSE: =IF(condition, if true, if false)
- The condition uses the comparison operators =, <>, >, <, >= and <=, and the boundary value is where marks are lost: > leaves the limit out, >= includes it
- Text results go inside quotation marks, numbers and calculations do not, and the formula must start with an equals sign
Section 1A decision inside a cell
Sometimes a cell should show different things depending on the data. A mark of 50 or more should say Pass. A smaller mark should say Fail. A shop wants commission paid only when sales are high enough. The IF function makes that decision for you. It checks a condition, then shows one result if the condition is true and a different result if it is false. It is the spreadsheet version of If-then-else in pseudocode: If the mark is at least 50 then show Pass, else show Fail.
Section 2The three parts of IF
The pattern is =IF(condition, result if TRUE, result if FALSE). The three arguments sit inside one set of brackets, separated by the list separator (a comma in most set-ups). For example, =IF(C2>=50,"Pass","Fail") reads: if the mark in C2 is at least 50, show Pass, otherwise show Fail. Here's the trick: say it out loud in the order it is written. Condition first, then the TRUE answer, then the FALSE answer. Swapping the last two flips every result.
Section 3Comparison operators: building the condition
The condition compares two things, usually a cell address and a value, using a comparison operator. The result is always TRUE or FALSE. = equal to, <> not equal to, > greater than, < less than, >= greater than or equal to, <= less than or equal to. The cell is on the left and the limit on the right, so C2>=50 means 'C2 is 50 or more'. If C2 holds 35, then C2>=50 is FALSE and IF picks the third part. Easy to mix up: a single = in a condition means 'is equal to'. It is not the equals sign at the start of the formula.
Section 4Boundary values: > or >=?
The most common mistake is at the edge. If the pass mark is 50, a student with exactly 50 should pass. So the condition needs >= (50 or more). With > only (more than 50), a mark of 50 fails. Watch out: read the wording of the question. 'Exceeds' and 'more than' mean >. 'At least' and 'or more' mean >=. 'Less than' means <, 'at most' and 'or less' mean <=. Always test your formula with the boundary value as well as numbers on either side of it.
Section 5What can the results be?
The two results can be text, a number, or a calculation. Text goes inside quotation marks: "Pass", "Reorder", "Child fare". Numbers are typed plainly: 500 or 0. A calculation can use cell addresses: B2*0.05. For example, =IF(B2>40000,B2*0.05,0) gives 5% of the sales when sales are over 40000, and 0 otherwise. Without quotation marks, the spreadsheet thinks Pass is a name it should know about and shows an error. The quotation marks tell it 'this is just words'. A condition can compare text too, such as =IF(F2="Yes","Paid","Owing"), with the word in quotation marks.
Section 6Typing, copying and testing the formula
Check four things when you type an IF: it starts with =; the brackets match; there are exactly two separators dividing the three parts; and any words are in quotation marks. Once one cell works, copy the formula down the column so every row gets its own answer. Each row's formula looks at its own row's data. (The rules for how cell addresses change when you copy are in the topic on relative and absolute addressing.) Because it uses cell addresses, the result changes by itself when the data does. If a mark of 49 is corrected to 51, the cell beside it switches from Fail to Pass with no retyping.
Section 7Putting it together
To build an IF, ask three questions. What am I testing? What should show if the answer is yes? What should show if the answer is no? For a Mandeville shop deciding delivery: orders under 5000 dollars pay a delivery charge of 500 and larger orders get free delivery. Condition: order less than 5000. TRUE result: 500. FALSE result: 0. Formula: =IF(B2<5000,500,0). An order of exactly 5000 is not less than 5000, so the condition is FALSE and the delivery is free. Check that your formula agrees with the rule you were given.
Examples
A teacher in Portmore enters four marks in C2 to C5: 72, 50, 49 and 35. The pass mark is 50. She types =IF(C2>=50,"Pass","Fail") in D2 and copies it down to D5. (a) State what each cell in D2 to D5 shows. (b) Explain why the mark of 50 shows Pass. (c) A colleague writes =IF(C2>50,"Pass","Fail") instead. What does it show for 50? Suggest a different condition that gives the same results as the teacher's formula for whole-number marks.
(a) Test each mark against C2>=50. 72: 72 is at least 50, so the condition is TRUE and D2 shows Pass. 50: 50 is at least 50, so TRUE and D3 shows Pass. 49: 49 is less than 50, so FALSE and D4 shows Fail. 35: FALSE, so D5 shows Fail. (b) The operator >= means 'greater than or equal to'. A mark equal to the pass mark satisfies the condition, so the formula picks the TRUE result. (c) With >, a mark must be more than 50. For 50 the condition 50>50 is FALSE, so the colleague's formula shows Fail. A whole-number mark of 50 or more is the same as a mark greater than 49, so =IF(C2>49,"Pass","Fail") gives the same results for whole marks. Using >= with the actual pass mark is clearer, though.
A shop in Mandeville pays sales staff 5% commission only when their monthly sales are over 40000 dollars. Monthly sales are in B2 to B5: 52000, 40000, 38500 and 61250. In C2 the shop types =IF(B2>40000,B2*0.05,0) and copies it down to C5. (a) Find the value each cell in C2 to C5 shows. (b) Find the total commission paid. (c) The owner decides that staff with exactly 40000 should also earn commission. Write the new formula for C2, and state the new value in C3 and the new total.
(a) For each row, test B>40000 and choose the result. B2 = 52000: TRUE, so C2 = 52000 × 0.05 = 2600. B3 = 40000: 40000>40000 is FALSE (it is equal, not greater), so C3 = 0. B4 = 38500: FALSE, so C4 = 0. B5 = 61250: TRUE, so C5 = 61250 × 0.05 = 3062.5. (b) Total commission = 2600 + 0 + 0 + 3062.5 = 5662.5 dollars. Check: only two staff passed the condition, and 5% of their sales is 2600 + 3062.5. (c) The condition must include 40000, so use >= : =IF(B2>=40000,B2*0.05,0). Now C3 = 40000 × 0.05 = 2000. The new total is 2600 + 2000 + 0 + 3062.5 = 7662.5 dollars. The only thing that changed was the operator, which shows how much the boundary matters.
Now let's water it
Session runs notes to flashcards to quiz back-to-back.
Where this comes from
- CSEC Information Technology Syllabus (CXC 30/G/SYLL 08, revised 2000, 2008, 2013) · Caribbean Examinations Council (CXC) · Section 7, Specific Objective 3 · Syllabus scope
- LibreOffice Help, Calc function reference pages · The Document Foundation · Page 04060105, IF, checked against (https://help.libreoffice.org/latest/en-US/text/scalc/01/04060105.html) · Facts
- Calc Guide 7.6 (LibreOffice 7.6 Community) · The Document Foundation (LibreOffice Documentation Team) · Chapter 8, Comparison operators and the IF function, checked against (https://documentation.libreoffice.org/assets/Uploads/Documentation/en/CG7.6/CG76-CalcGuide.pdf), pages 274-275 · Facts
- Calc Guide 7.6 (LibreOffice 7.6 Community) · The Document Foundation (LibreOffice Documentation Team) · Chapter 8, Understanding the structure of functions, checked against (https://documentation.libreoffice.org/assets/Uploads/Documentation/en/CG7.6/CG76-CalcGuide.pdf), page 288 · Facts