1 00:00:00,520 --> 00:00:05,090 Now that you have a solid understanding of sum, average and median. 2 00:00:05,090 --> 00:00:09,080 Lets introduce a new function, the if function. 3 00:00:09,080 --> 00:00:12,890 If is a pretty foundational concept in computer programming and 4 00:00:12,890 --> 00:00:16,430 not surprisingly also important in spreadsheets. 5 00:00:16,430 --> 00:00:21,010 If is a conditional function that returns a value based on logic you put 6 00:00:21,010 --> 00:00:22,570 in the function. 7 00:00:22,570 --> 00:00:27,220 For example, say you wanted to know how many years certain countries had 8 00:00:27,220 --> 00:00:32,410 populations less than 10 million people or how many days a stock price was higher 9 00:00:32,410 --> 00:00:38,530 than a \$100 ,or how many pieces of wood had a width of exactly three inches? 10 00:00:38,530 --> 00:00:43,360 You can answer all of these questions and many more using the if function. 11 00:00:43,360 --> 00:00:45,530 Let's take a look at the function syntax and 12 00:00:45,530 --> 00:00:47,360 then walk through a couple of examples. 13 00:00:48,430 --> 00:00:50,230 >> So again, we select a cell. 14 00:00:51,370 --> 00:00:54,255 Hit Enter, write the equals sign. 15 00:00:54,255 --> 00:01:02,160 Then IF, then parenthesis and we can see the assistance below. 16 00:01:02,160 --> 00:01:05,910 Logical expression can be many things, for example 17 00:01:05,910 --> 00:01:10,280 you can test if the values in two cells are the same using the equality operator. 18 00:01:10,280 --> 00:01:12,990 Or you can test if two values are not the same. 19 00:01:12,990 --> 00:01:15,680 You'd use an inequality operator and so forth. 20 00:01:15,680 --> 00:01:19,430 The example that Google Sheets has given is text based. 21 00:01:19,430 --> 00:01:21,760 But note the syntax. 22 00:01:21,760 --> 00:01:24,350 If a logical expression, comma, 23 00:01:24,350 --> 00:01:29,880 then the value that is returned if it's true, the logical expression is true. 24 00:01:29,880 --> 00:01:33,740 Then a comma then a value that's returned if the logical expression is false. 25 00:01:34,900 --> 00:01:37,920 So let's walk through an example of this together. 26 00:01:39,890 --> 00:01:46,670 In this cell, we've written a formula based on if that says, 27 00:01:46,670 --> 00:01:51,550 if cell A9 is equal to the text Happy, 28 00:01:52,800 --> 00:01:57,730 then if true, return the text that says A9 is Happy, and 29 00:01:57,730 --> 00:02:02,410 comma, then if it's not true, return the text that says A9 is not Happy. 30 00:02:03,800 --> 00:02:11,960 So we can see here cell A9 is not Happy, so this is returning A9 is not happy. 31 00:02:13,280 --> 00:02:16,430 What happens if I actually write Happy in cell A9. 32 00:02:16,430 --> 00:02:22,350 You can see that this automatically changed to read A9 is happy. 33 00:02:22,350 --> 00:02:25,820 So I can undo that, A9 is not happy. 34 00:02:25,820 --> 00:02:27,960 I can redo it, A9 is happy. 35 00:02:29,050 --> 00:02:31,470 Let's look at another example. 36 00:02:31,470 --> 00:02:38,534 If E8 is equal to 4, then return 1. 37 00:02:38,534 --> 00:02:40,745 If it's not return a text, try again. 38 00:02:43,233 --> 00:02:44,620 So it's return and try again. 39 00:02:45,720 --> 00:02:49,940 If I make this 4, now it's 1. 40 00:02:49,940 --> 00:02:52,670 5, back to try again. 41 00:02:53,870 --> 00:02:57,663 Notice for text, that you have to put it in quotation marks, or it won't work. 42 00:03:00,251 --> 00:03:01,640 You get an error. 43 00:03:01,640 --> 00:03:03,930 And the description of the error is formula parse error. 44 00:03:03,930 --> 00:03:05,630 For a beginner, that's not very helpful. 45 00:03:05,630 --> 00:03:08,516 But just note that when you're writing text and formulas, 46 00:03:08,516 --> 00:03:10,251 they have to be in quotation marks. 47 00:03:17,862 --> 00:03:21,217 We can use this if function in another way as well, so 48 00:03:21,217 --> 00:03:24,400 let's just show you one more example. 49 00:03:24,400 --> 00:03:28,790 Where instead of an equality or an inequality we have a greater than. 50 00:03:28,790 --> 00:03:31,820 So what I'm gonna do is I'm gonna write here, if. 51 00:03:33,760 --> 00:03:41,800 And I wanna display all the pieces of wood that have heights greater than three. 52 00:03:41,800 --> 00:03:48,280 So if A6 is greater than 3, then I'm going to return true. 53 00:03:50,030 --> 00:03:57,128 If it's not, Too small, for example. 54 00:03:57,128 --> 00:03:59,913 So here A6 is greater than 3, 55 00:03:59,913 --> 00:04:05,280 in this case it's actually 6, so it returns a value True. 56 00:04:05,280 --> 00:04:10,910 Now I'm gonna copy this formula, All the way down. 57 00:04:12,160 --> 00:04:17,730 And we can see that through relative referencing, 58 00:04:17,730 --> 00:04:22,560 we've been able to carry this formula all the way down and for every piece of wood 59 00:04:22,560 --> 00:04:25,760 that is not greater than three, we've got the result too small.