How to do Area calculations in Tableau [ with correction ] : New in Tableau 2021.2
I got it wrong, owned up to it, and then showed you exactly how Tableau's new AREA function really behaves.
- Never assume that data from a trusted source is correct, and always validate a conclusion before publishing it.
- Tableau 2021.2's AREA function calculates the area of a polygon, taking a geometry dimension and a unit ('metres', 'kilometres', 'miles' or 'feet').
- You can connect directly to shape files (.shp) in Tableau natively, and double-clicking a geometry field instantly builds a map.
- The AREA function only gives an estimate over large or curved geographies because flattening the earth's curvature introduces variance, so it's most reliable for small, simple shapes like parks and playgrounds.
- You could drive the unit argument with a parameter to switch dynamically between metres, feet, kilometres and miles.
0:00Hey, it's Tim here today, different kind of
0:02video, I'm actually uploading a correction.
0:04Yes. When I
0:05made a video about the error calculation in
0:072021.2, there was essentially a mistake
0:10that I made, and it
0:11was an assumption. Now what actually
0:13happened in this error calculation is I had
0:15a data set
0:15from a London data provider. And in that
0:18data set that actually pre calculated the
0:21area. And the
0:21reason I was looking for this data set is
0:23because I needed some way of validating
0:25tableau's error
0:26calculation against another data set. So
0:28the assumption I made was that the company
0:30that
0:30produced this data had done it correctly.
0:33Now it actually turned out that when I did
0:35this comparison
0:36in the video, you can see here at seven
0:38minutes 55, I'm actually comparing seven
0:40side by side,
0:41the two calculations, and you can see that
0:43I'm calling out that the tablet error
0:45calculation
0:46is way off, actually sent this feature into
0:48tableau. And they actually took some time
0:50out
0:50to look at the data set and to look at the
0:52error calculation. And it turned out using
0:54another tool
0:55that the error calculations in the data
0:57source I was using was actually incorrect.
1:00And therefore,
1:00I came to the conclusion that the error
1:02calculation was not as accurate as it
1:04should be
1:05over certain types of geographies. And in
1:07some cases, you can see here side by side,
1:09it maps pretty well. But there was just a
1:11few object IDs here that were generating
1:14areas that just weren't matching. And that
1:16wasn't the fault of tableau is actually the
1:18fault of the
1:18error calcs that were done in this data set
1:21. Now, it is really important lesson, which
1:23is to never
1:24make the assumption that the data source
1:26that you find from a trusted source is
1:27always correct.
1:28And number two, I jumped to a conclusion
1:30without first validating it before I
1:31released the video.
1:32Now in order to fix this, what I'm actually
1:34going to do is I'm going to play the video
1:35again,
1:35I'm not going to re record the video. But I
1:37will put a note up in the section where I'm
1:39calling out
1:40the mistake or the issue with tableau's
1:41data source to actually validate validate
1:43that the
1:44issue here is not to do a tableau. And I
1:46sort of don't want to re record the video
1:48and then delete
1:49the old one because I think it's good to
1:51sort of fess up to your mistakes. And
1:53actually realize that
1:53we're all still learning. And at the end of
1:55the day, tableau did the due diligence and
1:57to make
1:58sure that the calculation was doing the
2:00best job it can. Now, if you're into some
2:03sort of detail
2:04about this, it's actually quite hard to do
2:06error calculations on something like the
2:08curvature of
2:09the earth, depending on the size of
2:11geography, you can get slight variances
2:13depending on how you do
2:14the calculation. So I'm not the expert on
2:16this, I'm going to maybe link to some
2:17articles in this
2:18description for this video. So you can go
2:20off and find out the complexities of doing
2:22that there's
2:23actually a tableau paper on hexagons and
2:25hex mapping and sort of showing the
2:27disproportionate
2:29behaviors that you can get and how you have
2:31to sort of correct for that over large
2:32areas. So I
2:33actually recommend you read that that's a
2:35proper in depth paper by people who know
2:36what they're
2:37talking about. And that can give you more
2:39context into this. But that's pretty much
2:41it for me,
2:41I just wanted to add this correction in
2:43front of the video, but upload the video as
2:45is rather
2:45than trying to sort of hide the fact that I
2:47got it wrong. So there we go, we all make
2:49mistakes. And
2:50hopefully you can learn from mine. Thanks
2:52for watching, and I'll catch you in the
2:53next video.
2:54Hey, Tim here in today's video, I'm taking
2:56you through a new feature in 2021.2. And
2:59that is the
2:59new area function, a new spatial function
3:02that allows you to calculate the area of a
3:04polygon.
3:04But before I get into this, be very careful
3:06with this. If you use this over large ge
3:09ographies,
3:10it's actually only giving you an estimate.
3:12I'll get into why that is in a second. Let
3:14's get stuck
3:15into this. So the first thing I'm going to
3:16do is I've actually gone to this website,
3:18when you're
3:18working with spatial data, it's always good
3:20to have a good sample data. And I've gone
3:22to this
3:22London data store to grab flood risk zones
3:25as calculated by the Environment Agency.
3:28Essentially,
3:28they figure out where there's a flood most
3:30likely to happen in London. And they've
3:32created a shape
3:33file or a bunch of polygons for us to use
3:35if we want to visualize that it's part of
3:37an open data
3:38initiative. Now, this was created three
3:40years ago, so it's nothing new. But I'm
3:41going to connect to
3:42this directly in Tableau, I've actually
3:44gone ahead and downloaded it to my desktop,
3:46so it's already
3:46there. So I'll just go back into Tableau
3:48here, and we'll just go ahead and use the
3:50spatial file. So
3:51if you've never used a spatial file before,
3:53it's actually this option here, it's
3:54essentially a type
3:56of file that has information about
3:57geography, that's the simplest way to sort
4:00of think of it.
4:00And so if I click on this, you'll see that
4:02I actually have the ability to open the
4:04file and
4:05shape files don't just come on their own,
4:07they tend to come with other supporting
4:08files. But the
4:09one file that we're interested in is this
4:11one, which ends in dot s HP. So if we click
4:14that and
4:14click open, you should see that Tableau
4:16handles this absolutely fine. It's been a
4:18native capability
4:19of Tableau to support these out of the box.
4:21So it's just right into this Tableau. And
4:23the great
4:24thing is that it works with everything
4:26including the data models. If you want to
4:27pair this up with
4:28other days that you have and find out where
4:30the properties are in certain London flood
4:32zones,
4:32you could it's an absolutely very simple
4:34thing to do. Maybe that's for another video
4:36. But
4:37nevertheless, we've connected to this data.
4:39Now I'm just going to go right into sheet
4:41one. And
4:41you can see that here on the left hand side
4:43, we've got all our fields. Now in Tableau,
4:46it's super
4:46easy to create a map, you just double click
4:48any geographical field, and it will do it
4:50for you.
4:51Where I know it's geographical is because
4:53there's this world icon to the left. So let
4:55's just double
4:56click that and see what happens. It's a
4:58geometry field and boom, we already have a
5:00map. Now, I know
5:01this is London, but it has some really poor
5:03context on here. There's nothing on the map
5:05that suggests
5:06this is London. So let's customise this map
5:08before we carry on. Let's go to map layers
5:10at the top.
5:11Let's choose a more interesting map, let's
5:13choose streets. And this should start to
5:16give us a little
5:16bit more sort of a vibrant map. I'll sort
5:18of dial down the the wash in the background
5:21so that the
5:22visualisation is actually what we see
5:24prominently. But it's nice because I have a
5:26literal label that
5:27says London, have all the London boroughs
5:29and towns. So if you're familiar with
5:31London, this
5:31should start to look very familiar for you.
5:33But nevertheless, we're here to look at
5:35this new
5:35function. So I'm going to close this map
5:38layers option. And when I look at this data
5:40, if I just
5:40open this little data preview for that, I
5:43just went over here, that clicking that
5:45little table
5:46icon opens up this data preview that you
5:48can see. And you can see that there's a
5:49bunch of different
5:51shapes, and each one has an object ID. So
5:53what I'm going to do is I'm actually going
5:55to use that
5:55object ID. Now, the other thing to bear in
5:58mind is that I've actually already got the
6:00area in here.
6:01And the reason I want this in here is
6:02because I want to show you how accurate
6:04this area calculation
6:05actually is. In essence, the bigger the
6:08proportion of area, the less accurate this
6:10is going to be.
6:11And we'll kind of do a quick calculation
6:12just to see how much it sort of varies. So
6:15let's,
6:15let's go ahead and look at that. So let's
6:17go ahead and let's just close this. And now
6:20what I'm going
6:21to do is grab objects ID and just put it on
6:23colour so that each and every one of these
6:25polygons gets
6:26its own sort of colour. Now, the reason
6:28this isn't quite showing what I wanted to
6:30show is because I
6:31need to bring in more context. So what I'm
6:33going to do is I'm going to actually drag
6:35the object ID
6:36up into this table section. What's
6:38happening here is that the object ID is
6:40being treated as a number.
6:42So it's actually aggregating it. I don't
6:44want that. I want it to treat it as like a
6:45text field. So
6:47what I'll do is I'll cheat on it a little
6:48bit. I'll actually drag object ID up here.
6:51You'll see
6:51that it changes two dimensions when I do
6:54that. And now it's blue. And now what I can
6:56do is put
6:57that on colour. Now each and every one of
6:59those shapes has its own unique colour. And
7:02if I hover
7:02over that, you can see that it sort of
7:04activates and we're now able to click on
7:05them and interact
7:06with them. So that's working really, really
7:08well. Now, the other thing I'm going to do
7:10is I'm also
7:11going to just look at this table again, and
7:13just see what's also useful to bring
7:14probability band.
7:15That's probably telling you how much of a
7:17flood risk zone this is. So what I'll do is
7:19I'll put it
7:20on a tool set because I want this in the
7:22tool tip when I hover over something. So
7:24you can see that
7:25some of these are very low, some of these
7:27are very high. And it essentially changes
7:29depending on the
7:30part of the map that we click on. But it's
7:33sort of working. Anyway, we've got enough
7:36information
7:36on our visualisations. Let's go ahead and
7:38actually use this function. So it's a super
7:41simple function.
7:41It's actually one of these functions in
7:43Tableau all together. So if I just type in
7:46area, you see
7:47that you get a little hint here of what you
7:49should use. So you should use a polygon
7:50dimension in here
7:52and the units that you want to measure the
7:53area in. So in this case, my polygon
7:55dimension is this
7:56geometry field. So I can actually just drag
7:59it in and drop it right there in Tableau,
8:01then hit a
8:01comma. And I'd like this done in metres. So
8:04I'm just going to do two speech marks
8:05single or double
8:06works perfectly fine. Enter an M and then
8:09now that's our calculation done for metres.
8:11You can
8:12also do kilometres and miles, you just have
8:14to find the appropriate documentation for
8:16that. In
8:17fact, let me bring that on screen now
8:18actually, you know, when I do these videos,
8:20I literally
8:21have the documentation to the left of me.
8:23So you can see here, the different
8:25dimensions you can use
8:27so metres, kilometres, miles and feet,
8:29those are all the different syntaxes you
8:31can use. So you
8:32could actually probably use a parameter to
8:34switch between those. So you can calculate
8:36all of them
8:38and then just put a parameter in here to
8:39change metres to feet and then it will
8:40dynamically
8:41recalculate it rather than using a
8:43parameter to change the different
8:44calculations. But nevertheless,
8:46this is really cool. And we've got the area
8:49in metres squared, I just put empty as a
8:52shorthand,
8:53and we'll hit apply. And now what I want to
8:55do is I want to grab the area in metres
8:56squared and the
8:57shape area and put them both on the tooltip
8:59so we can actually see what those two are
9:01like. Okay,
9:02now that's working, all the calculation is
9:04done. And now when I hover over this, you
9:07can actually
9:07see the two values, you can see here area
9:09in M2 and the shape area. Now there are
9:12subtle
9:12differences, okay, and we're talking
9:14roughly 1000 metres squared here or there,
9:17depending on how big
9:18the geography is. If I go down here to a
9:21slightly smaller one, you'll notice that
9:23the differences
9:24become larger, the bigger the geography,
9:26but if we go to a really small one, let's
9:28go to one of
9:28these ones here, they're very, very small
9:30differences. So essentially, the problem
9:33with
9:33this function is that the shape of the
9:36world is not flat. If you're a flatter,
9:39this is not the
9:40video for you. But essentially, the world
9:42is a curved platform. And the more curved
9:44something is,
9:45the harder it is to actually calculate the
9:47area because you've got to sort of flatten
9:49it out. And
9:49by the time you do that, it doesn't
9:51actually make a perfectly flat shape. So
9:53what this area
9:54calculation doing is sort of trying to
9:56compensate for that, but it's not really
9:58doing it sort of
9:58fully, you need a little bit more of a
10:00complicated sort of calculation in order to
10:02do that. Whereas
10:03the error calculation in this spatial file
10:05has actually been calculated by the
10:07environment
10:08agency using fairly accurate mechanisms,
10:10because they have to know the size of these
10:13things,
10:13things like insurance policies are based on
10:15these ratings. So they have to be pretty
10:17accurate as to
10:18how they work. So you can see there's a big
10:20difference. And what I'm going to do is I'm
10:22actually just going to build a very, very
10:24simple visualization, I'm just going to
10:26bring in object ID
10:27at all of them. And what I'm going to do, I
10:29'm going to bring in the area in meter
10:32squared,
10:33and I'm going to bring in the shape area in
10:34the table next to it. So you can just sort
10:37of see
10:37some of these side by side. Now, some of
10:39them are very similar, some of them are
10:42very different.
10:43For example, this one is sort of
10:44interesting, because, you know, this one's
10:47just so way off. So
10:48why is Tableau getting that so different,
10:50whereas some of these, they're almost so
10:52bang on. So it
10:53could be to do with the shape and the form
10:55of the particular geography could be a long
10:58versus thin
10:59versus, you know, you don't know all these
11:01sort of variables. So in generally speaking
11:03, you can see
11:04that this is an estimate. But it's just
11:06worth being careful and knowing that this
11:08is an estimate,
11:08because you see that this particular object
11:10, it says it's 12. But the actual area is
11:13calculated
11:13by the environment agencies 224. So that's
11:16just something to be aware of. Now, what
11:18you could do
11:19is you could actually sort of create a
11:21table. So if I was to sort this from the
11:24largest shape area
11:26to the smallest, you can see that some of
11:28these are just way off. So it's definitely
11:31one to be
11:31sort of wary of and to be really careful
11:34how you're sort of relying on this function
11:36,
11:37because it can actually throw some of your
11:39things off if you rely on it too much. What
11:41are the best
11:41use cases? Listen, if you're measuring
11:43things like playgrounds, parks, this is
11:45perfectly fine,
11:46you know, nice, simple geographies, polyg
11:49ons, shapes, simple geographies, if you're
11:51measuring
11:51the area of let's say, a river that travels
11:53over a long distance, well, that's going to
11:56be a little
11:56bit more tricky, because of course, over a
11:59longer distance, there's more curvature.
12:01And the shape
12:02area or area calculation is only going to
12:04be able to calculate it to sort of one
12:05extreme. So you
12:06will get less accuracy for polygons that
12:09span really large distances and large ge
12:12ographies.
12:13But I'm not a scientist here, I'm just sort
12:15of going off what what I see and what I
12:17know I've
12:17asked the devs about. But it's definitely
12:19one to just watch out for. And some of
12:21these I think I
12:22think there's probably just an issue with
12:23the polygons, you can see that that says 20
12:26. And then
12:26it's just completely way off. So it's not,
12:28it's not sort of an exact science. And I
12:31need to get
12:31more into this to really understand, you
12:33know, why are some of these really, really
12:35close and why
12:36some of them really, really far off. The
12:38figure on the right is the accurate one
12:40from the Environment
12:40Agency, I just wanted to get that there
12:42before I show you a calculation. And I tell
12:44you that it's
12:45correct as fact and then he has a slight
12:47margin. And actually, some of these have
12:49huge margins. So
12:50I'd be interested to see what you think of
12:51that. If you're a geographer, or you
12:53actually use spatial
12:54functions all the time, I'd love to know.
12:57And if you know anything about why this is,
12:59why is this
13:00calculation in Tableau getting it so
13:02different to the values that have been
13:03calculated by the
13:04Environment Agency, what I will do is I'll
13:06put a link to this data set and maybe you
13:08can tell me
13:09if you've got some insights to why that is.
13:11But I'd love to get to know more. Alright.
13:13Anyway,
13:14that's that's it. We have arrow functions
13:17in Tableau. Now you can use these over
13:19simple
13:19geographies and they're going to be really,
13:20really useful. Thanks for watching. If you
13:22've enjoyed
13:23this video, be sure to check out some of
13:24the other videos in 2021.2 on this channel,
13:27as well as other
13:28versions of Tableau from way past all the
13:30way to functions in Tableau. I cover
13:31everything so get
13:32in touch. Let me know what you'd like to
13:34see and if not, hopefully I'll catch you in
13:36the next one.
Future-proof your career https://n1d.io
| This video includes a correction of a previous video that’s now unlisted: https://youtu.be/HsKJMCKoQY4
Links to posts on the challenge of calculating area and the impacts of projection distortion.
Tableau paper: https://research.tableau.com/paper/shapes-plane-evaluating-impact-projection-distortion-spatial-binning
Wikipedia article on distortion: http://wiki.gis.com/wiki/index.php/Distortion
You can now perform area calculations in Tableau. This is great for calculating the area of small polygons such as parks, building plots and more. be careful though, over large geographies the calculation doesn’t compensate for the curvature of the earth so it’s only an estimate.
Tableau release notes: https://j.mp/3xVS7jw
”In 2020.2, we’re introducing the Spatial Area function. Use the Spatial Area function to find the area of any polygon in a geographic role. For more information.”
0:00 Correction
2:54 Video starts here
7:35 How to do the area calculation
9:08 Comparing the calculation to pre-calculated values Share feedback and Suggestions: https://tableautim.canny.io/suggestions -
Join this channel to get access to perks:
https://www.youtube.com/channel/UC7HYxRWmaNlJux-X7rNLZyw/join ----------
(C) 2023 TN-Media LTD. No re-use, unauthorized use, or redistribution, of this video without prior permission.