Calculations Video Lecture Transcript This transcript was automatically generated by Zoom, so there may be discrepancies between the video and the text. 12:38:20 Hi! Everybody! Welcome back in this video. We'll talk a little bit more in depth about tableau calculations or calculated fields. 12:38:29 So these are custom, custom calculations using the variables that are loaded within your tableau environment. 12:38:37 So instead of going through this slide, my slide, I think it will be easier just to see me do it, and then you can follow along with the slides on your own. 12:38:42 If you'd like so now I'm gonna be over in tableau. 12:38:45 I'm for this example. I'm using the super store sales data that tableau provided. 12:38:51 It in the data folder of the Repository. 12:38:55 I'm going to just be making calculated fields. 12:38:57 I will not be making a visualization, so there will be no saved complete workbook. 12:39:03 This is just showing you how to make calculated fields, so we can go ahead and create account. Calculated fields. 12:39:11 So to do that I right clicked, or on a Mac. 12:39:13 I can control clicked , the data area of the tableau app and then this popped up this little top area. 12:39:21 Here is the name, so I could call this calculation one which is the default. 12:39:28 I won't call anything else, because I don't have any other. 12:39:29 Grand ideas, of what a calculation I'll be making, so I'll just keep this calculation. One. 12:39:33 But typically you'll want to name it something that you know what it is. 12:39:38 The next thing is this area down here below this dividing line is the calculation area. 12:39:43 This is what allows you to add calculations. Now, a couple things about the syntax of a calculation within tableau. 12:39:52 So 2 slashes. I'm not sure if they're back or forwards. 12:39:55 I always forget these are, let's see. 12:40:01 I think this is comments, let's go ahead and double check with nice slideshow. 12:40:07 So the. 12:40:10 Okay. So the 2 slashes these slashes are denoting comments. 12:40:16 So this is a comment. And then after that we can go ahead and we can go ahead and add other stuff. 12:40:25 So if we would like to indicate a field on here. 12:40:27 So perhaps we want to do sales. This fields are the name of the field. 12:40:36 So for us sales contained in square brackets. 12:40:41 The other thing we might notice is, there are things that are keywords, so keywords are words like if or words like is null. 12:40:52 So if it's like a function or if it's like a logical statement, keywords are always all capitalized. 12:40:58 So sales. You know this is a fields are in square brackets with their names, so maybe like instead of this is a comment. This is a comment. 12:41:11 And then fields are always stored in square brackets. 12:41:19 And then keywords are always. 12:41:27 All upper case. And so then we've got, you know. 12:41:30 If else, then is no? 12:41:38 Etc. So like is null here. You can tell us a little bit different from if else, then so because it's highlighted blue and has parentheses after it is a function, and we'll talk a little bit more about those later in this video okay, so we've 12:41:54 seen, some examples, so why don't we go ahead? 12:42:00 And do you a real calculation learning about? If so, if is a statement that if you have some logical condition that's met, then something is is calculated. 12:42:12 So, for instance, here is, and example of an if statement. 12:42:20 So we have capital. I. F, for if and maybe we will check if our profits maybe want to see if we're profitable, so is profit greater than 0. 12:42:32 And then, if so, well, you would return. Maybe we wanna return the string like profitable. 12:42:41 And then, once you're done with an if so, if then, you put the logical statements, then you put what you want to happen after the logic. 12:42:52 If the logical statement is true, then you put like what you'd like to return. 12:42:55 So after that, when you're all done with a regular if statement, you have to put the keyword end. 12:43:01 Okay. Now, we're gonna have an example of an if else statement. 12:43:12 So, if so, this is the same. So if profit is greater than 0, then we're profitable. 12:43:25 But instead of putting an end, if we want to do something for profit being 0 or less than 0, we can put else. 12:43:34 And then, after the else we'll put what we want, returned. 12:43:37 We'll put not profitable. 12:43:41 And maybe a frowny face, because we're sad that we're losing money. 12:43:46 Okay? And then, after the else statement, we have to put the end keyword. 12:43:51 Okay. Now, here's an example. So maybe you wanted to check multiple things. 12:43:56 So an example of, if else, if else. So if we wanted to check multiple logical statements in a change. So maybe we want to check if we're profit is, say, greater than a 100, then maybe we're thinking we're really. 12:44:16 Profitable. 12:44:19 Smiley face. Okay? Else if? 12:44:26 Maybe, are we just wanna be, you know, profitable at all. 12:44:31 Then we might say, you know, little profitable. 12:44:39 Else, if our profit. 12:44:45 So just Al, sorry about that. We don't have to check anything just else. 12:44:49 Then we would say, not profitable. Brownie face, and then we need the end. 12:44:55 So now you know how to do, if if else, and then if else. 12:44:59 If so, if you do the if the logical statements followed by the keyword, then what you would like to return, followed by the keyword, and indicating that you're at the end of the statement, for if else you do, if but instead of having an end, at the end, you now have a new 12:45:20 line with else, and what you want returned, and then again, at the very end, you put end for is else, or if else, if else you do, if else, if and then again you end with the end okay, so this is the key this is the chain you could keep going, if you wanted, with additional else if just remember at the 12:45:43 very end. Whenever you're done with we are lucky you're out, if else ifs, you need to put an end at the very end. 12:45:49 Okay. So we've covered. Now, conditionals, let's go ahead and talk about and or not. 12:46:01 So here's a comment. This is an example of. And so, as an example, we could do roughly greater than 10. 12:46:16 And now this is one logic condition, one away profit greater than 10, and then you put the keyword, and maybe we want a good volume of sales. 12:46:32 Okay. So this would be something that executes returns a true if both profit and is greater than 10, and sales is greater than 100. 12:46:44 So another one is, or an example of, or so. Now we could do. 12:46:51 Maybe we just wanna be profitable. So is our profit greater than 10, or it's also okay to us. 12:46:59 If we're as long, maybe we don't have a great profit. 12:47:02 But we are selling a lot of product or something. So this would return. A true if one of these, at least one of these is true, could be both. 12:47:12 And then, finally, we have an example of our last logical condition, which is a not so not. 12:47:21 Profit. 12:47:25 Greater than 10? 12:47:28 So this would return to true, if profit was less than or equal to 10, or in a false, if profit was greater than 10. 12:47:38 Okay. So and if you want multiple things to be true at the same time, or if you want at least one of the things to be true, and then not if you want the opposite of the thing. 12:47:50 Okay. So the last thing that we might want to check is, maybe there's a function. 12:47:57 So there's lots of built in functions within tableau. 12:48:01 So you'll notice here, there's this little arrow that I keep clicking so if you click the arrow, it tells you all the various functions that are available to you by default or in base tableau. 12:48:13 I guess so. For instance, you could click on Abs, and then it tells you what the function does and gives you an example. So you could type in. 12:48:21 Now Abs, which stands for absolute value, and we could put in the absolute value of profit. 12:48:29 Say, okay, not that that's useful. But now this will return. 12:48:31 The absolute value of profit, and if I save this one, we could see, you know, absolute value of profits. 12:48:44 Okay. And we could plot this. So maybe we're gonna pot this on the Y profit on the X, and we can like get rid of the aggregates. Okay? 12:48:58 And so now you can see the absolute values. 12:49:02 Alright! 12:49:04 So let's go ahead and go back and make a new calculated field. 12:49:11 A nice feature about tableau's calculated fields is, it will tell you when something's wrong. 12:49:17 So here's an example where I'm going to deliberately make a calculation. 12:49:22 So maybe I just want to. If I just put this it's not a complete. 12:49:25 If statement. So, you can see that it's telling me calculation contains errors, and then if you click this little red arrow, it will then provide you a message of why it thinks like why it's telling you. 12:49:37 There's errors, and then maybe what you might be missing. 12:49:40 So anytime you make a calculation if it says calculation contains errors, it will not run the way you want so good check after you write your calculation is just to make sure doesn't say I have errors, or does it say it's a valid calculation. 12:49:53 Now that doesn't mean it's going to do what you think. 12:49:55 It's going to do. But it just means that it will run without error. 12:49:59 Okay. So I think that's everything about calculations. So like just to go through the slides real quick and double check, I covered everything I wanted to cover. 12:50:20 Yep, okay. So that's everything. So now you know a little bit more about calculated fields and tableau. 12:50:27 These are incredibly useful. We're gonna learn a little bit more about them. 12:50:31 I believe in the next video, we'll learn about something called a level of detail express. 12:50:36 Which are used within calculations. All right, I hope you enjoyed this video.