Thursday, July 30, 2015

Flow Chart / Flow Diagram / Decision Tree in Tableau

There are two ways to go about building a flow chart/diagram or decision tree in Tableau.  You can either treat it as a scatterplot on a single worksheet, or you can think about using a dashboard as your canvas, and then float multiple worksheets on the dashboard to achieve the right shape/flow.

I first started exploring the former.  It is a similar technique to using background images in tableau and creating a lookup table for the x,y coordinates of the marks you want to plot on top of the image.  I quickly noticed two downsides with this:  1. You need to add more data in the form of a new table of x,y coordinates to your underlying data (to be joined or blended to your actual data) - there are obvious downsides to this; 2. You cannot use actions to trigger a drilldown to another worksheet by clicking on one of the numbers/marks in your flow chart (since all the marks are in one chart you cannot create a different filter action per mark (metric) in your chart - i.e. if I clicked on a metric I would want to be taken to another worksheet that has more details about that metric, and if I clicked a different metric I would want to be taken to a different sheet).

That's why I decided to try using the dashboard as my canvas and then make a separate worksheet for each metric, which could then be floated/arranged on the dashboard canvas.  Benefits of doing it this way:  1. You do not need to alter your data at all!; 2. You can create a separate filter action for each metric/worksheet that goes to a different destination worksheet in order to drill down and present more information about that metric.

That approach allowed much more flexibility in terms of how to arrange each mark in the flow chart, but one question remained:  How to get the arrows into the chart?  My first thought was to insert images of arrows into the dashboard.  If you are good with editing images and rotating them and sizing them to then be inserted into the chart then this is a viable approach.  However in my example I wasn't quite sure about how far each mark needed to be from one another and what angle each arrow needed to be at etc.  Since you cannot rotate images in a tableau dashboard you would need to create an image with arrow at exactly the right angle, which is a pain.  Perhaps if you only need straight arrows or already have a bunch of these images laying around then this might not be very painful.

Instead of images, I decided to use another worksheet to be the background or first layer of canvas which I could then add point annotations to to create my arrows.  A little formatting is necessary after you add the annotation (need to remove all the text, then format it to get rid of any borders and change the thickness and color to suit your needs) but they worked quite well.  The only trouble I had with this was even tough there was no text in my annotation, I needed to make the 'text box' quite wide so that once I floated a worksheet with one of the metrics over the top of it that I could still select the text box in order to move it around to get the start of the arrow to be in the right place.

Quick order of how to build this:
1. Build all the worksheets - one metric per worksheet
2. Build one more worksheet for the 'arrows'.  In order to add annotations there needs to be something in the view, so I just added number of records to text, changed transparency to make it clear (via Color shelf), removed the tooltip, and set the fit to 'Entire View'.  Dont add the annotations yet.
3. Create the dashboard: Add the Arrow worksheet first, then 'float' each of the other metrics and arrange them how you want.
4. Add the annotations to create the arrows from the dashboard itself.  I used Point Annotations.
5. Move them around and format them to your liking.

In addition to being a good example of this specific chart type, there are lots of nifty Level Of Detail (LOD) expressions used to calculate each of the metrics.  Things like 'Spend Per Customer', 'Avg Visit Value', 'Items Per Visit' and so on.  Since the granularity of the underlying data is at a per order per line item level, getting these type of metrics would require lots of sub-queries with multiple levels of aggregation to achieve before the LOD expressions were introduced in 9.0.  LOD's rule.

Two workbook's are available for download - one with just the flow chart and one with some filter actions to allow you to drill down to other detailed worksheets (I got lazy and only set up drilldowns for the first 3 metrics, but you will get the point).

Flow Chart: https://app.box.com/s/v06fqkxiufhwpyfhc3h3fba3rk83soqo
Flow Chart with Drill: https://app.box.com/s/mkf3ka80j8hy2cvtqxybo6rvk1918ruq

Any questions or improvements you've found, please comment below.

-The Don

No comments:

Post a Comment