If and nested i fs
Transcript of If and nested i fs
If and Nested IFs
@ntudigital
BLOG blogs.ntu.ac.uk/digital_practice
Getting to your session work files
1. Go to your laptop’s desktop2. Click the folder link to tdu-courses$ to open
Open the Excel Courses > IF and NESTED IF folderOpen the Excel IF formulas.xlsx file.
Any of the files can be opened in a Read only condition. They can't be re-saved into this folder. If you want to keep them then save them to your H drive.
You can also locate these files from your work computer:In a browser enter: \\opel\tdu-courses$
Logistics
• Toilets• Drinks and Refreshments• Fire Alarms• Questions
http://www.flickr.com/photos/major_clanger/382513/
http://www.flickr.com/photos/tonytoo/4692186465/
About the IF Function
The IF function does something based on a decision• If this condition is TRUE do this thing • If it is FALSE then do a different thing
Format: It is expressed in a formula
=IF( Condition, Do this if true,Do this if false )
= IF
( )
..,..,..
Equals means it’s a formula with the IF function
Brackets always come in pairs
Must have commas to separate the 3 arguments
Parts:
Simple IF formulas
=IF(A12=0, 35, 0)
The value in this cell If FALSE
In cell A10: evaluating numbers
If TRUE
Simple IF formulas
=IF(A12<=D20, 35, 0)
In cell A10: compare cell values arithmetically
Simple IF formulas
In cell A10: evaluating text
=IF(A12 = “Pass”, “Party”, “Try again”)
Simple IF formulas
In cell A10: cells can have empty or 0 as a result
=IF(A12 = “Pass”, “Party”, “”)
=IF(A12 = “Pass”, “Party”, 0)
Result if FALSE:
Result if FALSE:
(empty cell)
(zero in cell)
Exercise 1: IF exercises
See workbook: Simple IF exerciseExcel: Simple IFs tab
Nested IFs – these notes are in your workbook
• IFs are limited to 2 options
• Nested IFs allow multiple options• They can be long formulas but their principles are the same:
• There is only 1 equals sign • Each IF condition is tested for true from left to right• Use commas carefully• You must have an equal number of opening and closing
brackets• Add no spaces between the parts of the formula• Formulas are not case sensitive• The formula tests for the 1st true result, then exits
Nested IFs - format
This is where the next condition goes
=IF( , , )
IF( , , ))=IF( , ,
Note: • An equal number of open & closing brackets• There is only one equals sign
True?
True? True? False
Nested IFs - format
=IF(A12<50,“Fail”, )
This is where the next condition goes – after the comma
=IF(A12>69,“High pass”, )
=IF(A12<50,“Fail”, IF(A12>69,“High pass”,“Pass”))
2 IF conditions
Nested IFs – repeating format
= IF( , , IF( , , …
IF( , , IF( , , …
IF( , , IF( , , …
IF( , , , )))))))
True? True?
True? True?
True? True?
True? False
Nested IFs – note the order of the evaluation
=IF(A12>80,“distinction pass”, …
IF(A12>70,“high pass”, …
IF(A12>60,“good pass”, …
IF(A12>=50,“pass”, …
“fail”))))
Exercises – Nested IF exercises
See workbook: Nested IFs ExercisesExcel: Nested IFs tab
AND & OR nested IFs – for information only
=IF(Cond1, is true, IF(cond2, is true…,false))
The nested format we have used up to now is OR
OR
The nested format for AND
=IF(Cond1,IF(Cond2,”both agree”,”no agreement”))
AND
– these notes are in your workbook
SUMIF function – version 1 has 2 arguments
=SUMIF(B1:B4,20)
If a cell in the range satisfies the condition, then add it
B
21
12
20
29 =SUMIF(B1:B4,“>20”)
Result: 20
Result: 50
Note: If an argument contains text(<) it is enclosed in double quotes
SUMIF function – version 2 has 3 arguments
=SUMIF(A1:A4,”Red”,B1:B4)
If a cell in the range satisfies the condition, then the valuesin a different column of the same row are added
A B
Red 21
Green 12
Blue 20
Red 29
Result: 50
SUMIFS function – for multiple conditions
=SUMIFS(B1:B4,A1:A4,”Red”,C1:C4,”OK”)
Similar to SUMIF but allows agreement of multiple criteria.
If ALL are true then add Sum-range cell content to total
Result: 21
A B C
Red 21 OK
Green 12
Blue 20 OK
Red 29
If TRUE If TRUE SUM this &
Exercises – SUMIF and SUMIFS exercises
See workbook: SUMIF and SUMIFS exercisesExcel: SUMIF and SUMIFS tabs
COUNTIF functions – 2 arguments only
=COUNTIF(B1:B4,20)
If a cell in the range satisfies the condition, then count it
B
21
12
20
29 =COUNTIF(B1:B4,“>20”)
Result: 1
Result: 2
NOTE: Wildcard character searching: missing letters e.g. G**gle
COUNTIFS function - multiple conditions
=COUNTIFS(A1:A4,“red”,C1:C4,”OK”)
Similar to COUNTIF but allows for multiple criteria. If ALL are true then adds 1 to count total
Result: 1
A B C
Red 21 OK
Green 12
Blue 20 OK
Red 29
Exercises – COUNTIF and COUNTIFS exercises
See workbook: COUNTIF and COUNTIFSExcel: COUNTIF and COUNTIFS tabs
Excel Training @NTU
CPLD offers a series of Excel courses aimed to support your development• Spreadsheet Features (basic)• Conditional Formatting• Data Validation• Find & Replace• Pivot tables• Sorting and Filtering• Trimming, joining & selecting data• Creating visually effective spreadsheets *new• VLOOKUP
For booking a place on these course or to arrange a 45 min 1 to 1 Surgery session go to the CPLD website:
www.ntu.ac.uk/CPLD and look for the link to programme of events
Office Central
08 June 2016 26
https://now.ntu.ac.uk/d2l/home/295527
08 June 2016 27
Office Surgeries
http://ntu.ac.uk/apps/cpld/cpld_events/UI/events.aspx?&page=1&cat=2&kw=Office%20Surgery