26/10/20151 2.3 Selection Nested If structures & Complex Multiple Conditions.
If and nested i fs
Transcript of If and nested i fs
![Page 1: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/1.jpg)
If and Nested IFs
@ntudigital
BLOG blogs.ntu.ac.uk/digital_practice
![Page 2: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/2.jpg)
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$
![Page 3: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/3.jpg)
Logistics
• Toilets• Drinks and Refreshments• Fire Alarms• Questions
![Page 4: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/4.jpg)
http://www.flickr.com/photos/major_clanger/382513/
http://www.flickr.com/photos/tonytoo/4692186465/
![Page 5: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/5.jpg)
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:
![Page 6: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/6.jpg)
Simple IF formulas
=IF(A12=0, 35, 0)
The value in this cell If FALSE
In cell A10: evaluating numbers
If TRUE
![Page 7: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/7.jpg)
Simple IF formulas
=IF(A12<=D20, 35, 0)
In cell A10: compare cell values arithmetically
![Page 8: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/8.jpg)
Simple IF formulas
In cell A10: evaluating text
=IF(A12 = “Pass”, “Party”, “Try again”)
![Page 9: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/9.jpg)
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)
![Page 10: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/10.jpg)
Exercise 1: IF exercises
See workbook: Simple IF exerciseExcel: Simple IFs tab
![Page 11: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/11.jpg)
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
![Page 12: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/12.jpg)
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
![Page 13: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/13.jpg)
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
![Page 14: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/14.jpg)
Nested IFs – repeating format
= IF( , , IF( , , …
IF( , , IF( , , …
IF( , , IF( , , …
IF( , , , )))))))
True? True?
True? True?
True? True?
True? False
![Page 15: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/15.jpg)
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”))))
![Page 16: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/16.jpg)
Exercises – Nested IF exercises
See workbook: Nested IFs ExercisesExcel: Nested IFs tab
![Page 17: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/17.jpg)
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
![Page 18: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/18.jpg)
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
![Page 19: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/19.jpg)
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
![Page 20: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/20.jpg)
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 &
![Page 21: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/21.jpg)
Exercises – SUMIF and SUMIFS exercises
See workbook: SUMIF and SUMIFS exercisesExcel: SUMIF and SUMIFS tabs
![Page 22: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/22.jpg)
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
![Page 23: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/23.jpg)
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
![Page 24: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/24.jpg)
Exercises – COUNTIF and COUNTIFS exercises
See workbook: COUNTIF and COUNTIFSExcel: COUNTIF and COUNTIFS tabs
![Page 25: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/25.jpg)
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
![Page 26: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/26.jpg)
Office Central
08 June 2016 26
https://now.ntu.ac.uk/d2l/home/295527
![Page 27: If and nested i fs](https://reader031.fdocuments.net/reader031/viewer/2022030318/58f0fe1f1a28ab5f768b466b/html5/thumbnails/27.jpg)
08 June 2016 27
Office Surgeries
http://ntu.ac.uk/apps/cpld/cpld_events/UI/events.aspx?&page=1&cat=2&kw=Office%20Surgery