## March 22, 2016

# Tableau Tip Tuesday: How to Create Small Multiple Line Charts

For this week’s Tableau Tip Tuesday, I show you how I created the small multiples line chart of the race for the Republican presidential nomination. These charts are also known as panel charts. These can be quite tricky to make as sometimes you have to play around with the scope of your table calculation to get it quite right. This video should certainly get you started in the right direction.

Here are the two calculations you need to create the column and row dividers:

** Column Divider**

(index()-1)%(round(sqrt(size())))

** Row Divider**

int( (index()-1)/(round(sqrt(size()))))

Subscribe to:
Post Comments
(
Atom
)

Awesome stuff! When I follow this step-by-step, I am getting multiple dimensions per panel. I'm using Tableau 9.2. I've got everything computing by the dimension in the marks card. Not sure where I'm going wrong...I've also triple checked the column and row divider formulas.

ReplyDeleteAny ideas?

If I had to guess, you have nulls in your data set, which is what would cause that problem.

DeleteI did have nulls, but I cleared those out and still no luck. I created some fake data too and no luck.

DeleteIt works when I have the continuous date set to month, qtr, or year. But anything less than month, it puts all of my lines in one box. I really need it to be set on exact date/continuous for it to look right. Thanks for reading!

Zach, can you post a link to a workbook with the problem?

DeleteTry this link: https://www.dropbox.com/s/2dt016ur0mgblzv/Book1.twbx?dl=0

DeleteIt's fake data, but same problem persists.

Zach, one thing I noticed about your data set. Some Qcodes have data on a day, that other Qcodes do not. I think these gaps would create a similar problem to having nulls in the data for those dates.

DeleteThese differences exist at both the week and day level, but once you get up to the month aggregation level, all Qcodes have month level data, so that's when the divider calcs begin working.

If your original data source shares these same characteristics, then that's probably the source of the issue.

Interesting! Thanks for the reply Matt. So you're saying that basically all entries need to have the same date-ranges? That's definitely a problem with my original data source -- some values end in December 2015 while others may carry thru January 2016. I can see that being problematic now.

DeleteI should be able to join to a Time_Date_Dim table then and basically assign a "0" value where the date isn't available?

Since I'm still dissecting how the calcs work, I can't say for sure, but I'm pretty sure your solution will work.

DeleteIf there are at least nulls existing for every date/review/qcode combination in your original data source, you could use the ZN function in tableau to replicate your Reviews measure via a calc field and transform the nulls to zero's instead of filtering them out. That would save you the join work.

In trying to understand what's going on under the hood, I recreated the formulas in Excel and based on my generated Column/Row numbers, did a basic quadrant chart showing where the value for that data/date combination would go. Then I made a tableau workbook based on that data set and sure enough, the calcs basically break the plot because different Qcodes are plotting into different quadrants.

I don't know exactly why your data causes the calcs to break in the exact way seen in your sample workbook, so I'm hoping Andy will chime in and let us know if I'm missing anything :)

Here's a link to a folder with my example tableau file and excel workbook: https://www.dropbox.com/sh/n7sk6u6qqjmus9c/AAAtSAihBGhWXbQ283-8SRloa?dl=0

Hope this helps!

Thanks for the thorough review. I did go back to my source data and applied ZN to my formulas to force nulls to 0 and still no luck. The weird thing is that it appears to work when the date range is discrete (meaning it breaks the Qcodes up into it's 4 respective quadrants). But the discrete dates are clearly counterproductive to what the view is supposed to show.

DeleteI'll keep giving it the ol' college try. Thanks Matt!

Great post! I successfully combined this with the KPI Donut chart post to show building occupancy levels on our campus within one view. Any resources out there to help me understand what's going on with the row/column formulas? I enjoy learning the nitty gritty when I can.

ReplyDeleteWhich parts need explaining?

DeleteI'm assuming that tableau is drawing the data into the different partitions based on those calcs, but I'm not sure exactly how those formulas helping tableau determine that.

DeleteI joined in to help Zach in the thread above which lead me to some thought exercises about the formulas so I think I sorta get it now. Would still love to know if I'm missing anything.

DeleteAwesome! I always wondered how to make these small multiples matrices in Tableau. Now I know - thanks so much for sharing!

ReplyDeleteHi Andy!

ReplyDeleteGreat Tableau Tip!

Simo and I replicated it using Sample Superstore building panes of sales by subcategory by quarter, and stumbled upon some of the issues the other guys here already raised.

As "Copiers" subcategory didn't sell in the first quarter of the dataset (Q1 2011) the calculations tried to fix it just using Q1 2011 of the following subcategory (causing a translation of all the subsequent values for subcategories in Q1 2011).

To solve this, we changed the "quarter" tableau date in a string (str((YEAR([Order Date])))+"-"+str(DATEPART('quarter', [Order Date]))), and this works.

We guess this has to do with densification, and the tendency of Tableau to fill gaps in data when working with table calcs.

We thought this could have been an interesting use case to add in this space.

See you soon,

Simo and Nicco

This post is fantastic. I'm having a bit of trouble giving both the end points a value as well as showing the title at the top of the pane. I've set marks to pain to get the title, but ideally I'd set line ends to 'value' and bring in the title another way (replicating 'Cruz' or 'Bush' at the upper center of the pane).

ReplyDeletehi -- this is very helpful. I am 90% there but I can't get the labels (ie like your candidate names) to appear above each graph. What's the trick to that?

ReplyDeletethanks, noah

It's simply a constant line on the secondary axis. Download the workbook and you'll see how I did it.

DeleteHi Andy! Thanks a lot for this, its quite incredible and super useful!

ReplyDeleteI was wondering if you could help me out with a problem I have with the labels. I sometimes see two labels (with different values) or sometimes non at all. I was wondering if you had any idea where this could come from and how to fix it?

Thanks, Tom

Yeah, that's the tricky bit. It's likely the way you have your table calc set up.

Delete