Locked lesson.
About this lesson
In this lesson, you'll learn how to create custom measures for your Visualizations.
Exercise files
Download this lesson’s related exercise files.
23 - Creating Custom Measures.docx60.4 KB 23 - Creating Custom Measures SOLUTION.docx
57.9 KB
Quick reference
Creating Custom Measures
In this lesson, you'll learn how to create custom measures for your Visualizations.
When to use
Use this whenver you need to create a custom measure.
Instructions
Click the caret next to any Measure, and then select create, then select "calculated field".
To create a custom count of 0-1,000 and 1,000-2,000 and 2,000+ :
IF COUNT([dog_data.csv]) > 2000 THEN "2,000+"
ELSEIF
COUNT([dog_data.csv]) > 1000 and COUNT([dog_data.csv]) < 2000
THEN "1,000-2,000"
ELSE
"0-1,000"
END
Hints & tips
- Click the caret next to any Measure, and then select create, then select "calculated field".
- 00:04 Okay, in this video I want to show you how to create custom measures using
- 00:07 calculations.
- 00:08 Now this is a pretty broad topic, and
- 00:10 honestly I could spend probably the better part of an entire course just on this.
- 00:14 So we're not going to get into this in very great detail.
- 00:17 I'm just going to sort of whet your appetite and
- 00:18 show you a little bit what you can do to create a custom measure.
- 00:21 So we've really only got a couple of measures down here.
- 00:24 There is really only one that we've been using, this count, and
- 00:27 it's the entire count.
- 00:28 We can create a custom one and really sort of define exactly what we show.
- 00:32 So I'm going to click on the little caret here, and
- 00:34 let's go create a calculated field.
- 00:37 Now we can name this anything we want.
- 00:39 Let's call this a 1,000 breakdown.
- 00:44 So let's say we want to break these into chunks of 1,000.
- 00:48 We've been doing a lot of filters of dog count with 2,000 and above
- 00:51 because that really gives us more useful data that's visually pleasing to look at.
- 00:56 There's only a few dogs that have a count over 2,000 that makes the charter graph
- 00:59 looks nicer.
- 01:00 So we've been creating that filter over and over.
- 01:03 Well, we could just break that down in this custom measure.
- 01:06 So we've got this count.
- 01:08 This is the calculation that is creating this current count, right?
- 01:12 So what we could do is go let's create some logic.
- 01:15 So we could go if the custom count is, let's say, greater than 2,000.
- 01:20 That's what we've been doing up until now.
- 01:22 Well, what do we want to do?
- 01:23 Well, then let's create a label called 2,000+.
- 01:28 Now that will just create a label with only 2, 000 and
- 01:32 everything else will be listed as a null value.
- 01:36 So we could do that.
- 01:38 Now we need an end statement because an if statement always has an end statement.
- 01:42 So and we could see our calculation is valid.
- 01:45 Before we had that on there it was giving us an error.
- 01:48 Now we have our end statement so it's valid.
- 01:50 So we could do this.
- 01:50 We could just click this and boom, now its 1,000 breakdown has been added.
- 01:55 So if really quickly we want to add our breeds and
- 01:58 we want to add our 1,000 breakdown, you can see we have 2000+ as a column now.
- 02:05 And there's only a few dogs listed because,
- 02:07 as we've seen in the past, when we filter by 2,000 you only get a few dogs.
- 02:12 In fact, we could see that if we pull over our data our count as well.
- 02:18 And then if we wanted to filter this we could filter by 2,000 and
- 02:23 you can see 2000+ is the only thing listed.
- 02:26 I don't really want to do that so I'll pull this out of here.
- 02:30 So you'll see right here is 2000+,right?
- 02:34 That those few dogs, and everything else is null.
- 02:37 If we want to get rid of null we can always filter this.
- 02:39 So we can grab this and bring it over and just get rid of the null values.
- 02:43 And then, boom, we're just going to get that same group of 2,000 that we have
- 02:48 been filtering for earlier.
- 02:50 But now we've got a custom measure for it.
- 02:51 So kind of interesting.
- 02:53 We could break this down even further.
- 02:54 So let's clear this and let's modify this 1,000 breakdown.
- 02:58 So let's come over here and edit it.
- 02:59 So we've got a basic if statement.
- 03:01 We can keep going.
- 03:02 We can go else if.
- 03:06 And let me copy this little thing again and let's do another thing.
- 03:10 So we could go if that count is, let's say,
- 03:15 greater than 1,000 and
- 03:18 if the count is less than 2,000, right?
- 03:23 Then we want to say 1,000 to 2,000.
- 03:31 And then we can do a final else.
- 03:34 And we say everything else, then let's just go 0 to 1,000.
- 03:40 So we've created three things here, greater than 2,000,
- 03:43 from 1,000 to 2,000, and then from 0 to 1,000.
- 03:47 So if we say okay for this, and now we recreate this guy one more time,
- 03:51 pull this over, we can see we've got three buckets here, 0 to 1,000.
- 03:56 1,000 to 2,000 is kind of small, we might want to make this bigger.
- 04:01 1,000 to 2,000 and then 2,000+.
- 04:05 And if we actually pull in our data to see those results we could see,
- 04:11 That broken down.
- 04:12 Now we've got three side by side columns like this.
- 04:15 What we could do is just make one graph and make this measure a color thing.
- 04:23 So I'm not holding down the control button.
- 04:24 I'm just dragging this completely over here.
- 04:26 Boom, now we get a chart.
- 04:28 And we can see there's a little legend over here from 0 to 1,000,
- 04:31 from 1,000 to 2,000, and 2,000+.
- 04:34 And that is just those things we said right here in the quotation marks.
- 04:39 So 2,000+, see, 2,000+.
- 04:42 Here is 1,000 to 2,000.
- 04:43 There's 1,000 to 2,000, 0 to 1,000, 0 to 1,000.
- 04:48 So very cool, very easy way to make custom measures.
- 04:51 Now like I said, there's lots of different ways you can do this.
- 04:54 This is a huge topic this logic that we did in here, right?
- 04:59 I really kind of blew through this very quickly so
- 05:01 we could spend a lot more time talking about it.
- 05:03 And we're not because this is a very introductory course.
- 05:05 But if you wanted to learn more about these things you could sort of look this
- 05:08 up in the future.
- 05:09 It's probably a good thing to learn going forward after this course.
- 05:12 Getting into these calculations and the different code that you can write in here.
- 05:15 The great thing about Tableau is that you don't have to write code.
- 05:18 So a lot of people don't like to do things like this where this is really kind of
- 05:21 like code that we're writing, right?
- 05:23 But it's not that hard.
- 05:24 It's pretty simple structure, if, else, else, if, then.
- 05:28 And so it's really not that bad and it gives you a good
- 05:31 measure of control over exactly what is shown in your visualization.
- 05:36 So that's pretty cool.
- 05:37 So that's all for this video.
- 05:38 In the next video we're going to start to look at zip codes.
Lesson notes are only available for subscribers.