Sunday, 21 April 2013

A handy use of Attributes in Tableau - colouring waterfall charts

For a long time I've noticed the choice of making a Tableau field an 'Attribute' (as below, between Dimension and Measure) once it is in the view and not really known what to do with it, or had the need.


This week I found myself in a situation where I needed to use a Dimension in Colour, without that Dimension splitting up the view, and discovered one example where the 'Attribute' really comes into effective use. So here's the story:

I was making a waterfall chart at work based on some sub categories and needed to add the category one level up as colour. Since I can't divulge the actual data set I was working on I thought it might be useful to show a similar example using Superstore Sales. If you haven't made a waterfall chart yet in Tableau I'm not going to describe the process here but the online training video is very clear http://www.tableausoftware.com/learn/tutorials/on-demand/waterfall-charts-chart-type-8 . Below is the basic waterfall chart of profit split by product sub-category from Superstore Sales, just as shown in the video. Only I've sorted the categories by ascending profit.


Now in the video they go one step further and colour each bar red or green depending on whether the profit is positive or negative. In my case however I wanted to colour the bars by the categorisation level one level up, in the case of Superstore Sales simply Category. So the obvious thing to do is to drag Category into Colour on the marks card. But then this happens.....



....Eeeek! That's not what I wanted. So what's going on here is that the running total calculation is now being separated for each Category. In other words placing Category into Colour didn't just change the colours of the bars, it also added a an extra dimension by which the calculated fields would be based. So how do we get out of this conundrum? Well it turns out the easiest way is to change Category from a Dimension to an Attribute. Just right click on the marks card and select Attribute.


And that solves the problem, see below, and everybody's happy! The sub categories are coloured by category, but the structure of the original waterfall chart stays intact.



 Now I don't think I've fully realised the potential of how Attribute can be used, but this has certainly opened my eyes to how I might be able to use it effectively in future. Essentially any time where adding a Dimension to add visual clarity is also going to split the data set in way you don't desire, changing that Dimension to an Attribute might solve the problem. I'd suggest if you are interested in this then have a play with the function using all the different chart types, for example see what it does to packed bubbles:




4 comments:

  1. Hi Peter,

    A couple of other points about ATTR(): It's an aggregation that does a computation like IF MIN([Dimension]) = MAX([Dimension]) THEN [Dimension] ELSE * (a special version of Null) END. The extra complexity can cause ATTR() to be significantly slower in large data sets than just using MIN() or MAX() for use cases like the one you described. Where I get the most use out of ATTR() is in complex views, where I'll use ATTR() to returning a single value of a dimension and then if the level of detail in the view is changed in an unexpected way, say by adding another dimension, then ATTR() will cause calcs to begin returning * and/or Null.

    Cheers,

    Jonathan

    ReplyDelete
  2. Thanks Jonathan, following your comment I rebuilt using max(category) instead and as suggested it works in exactly the same way, but gives you the 'Ignore in Table Calculations' option. Seems to me this is something that could be made a bit clearer and intuitive.

    ReplyDelete
  3. So whats the basic difference between an attribute and a dimension?

    ReplyDelete

Note: only a member of this blog may post a comment.