Trellis Chart in Tableau

Consider the following line chart that shows total sales by quarter over four years and is broken down by the 17 sub-categories.

Pretend you are someone in your audience for this plot. Their response will be: what the heck is this crap! It’s too messy! The reality is almost no one is going to want to see a line plot with more than three lines. Your audience wants to trace a single line and it’s impossible to follow just one of the lines in this plot–even with unique color encoding. You’ve got to find a better way to communicate this information. One way we prefer to share this information is with a small multiple or trellis chart.

Tableau’s current process for creating small multiples or trellis charts is to add a dimension to rows and a second dimension to columns. But what if you want to do it with a single dimension? This tutorial show you how?

Step 1: Build Rows and Columns

Create a calculation called [INDEX].

// Index
INDEX()

Create an integer parameter and set the number of columns you would like to see. For the example we are using 5 columns. Call the parameter [Total Columns].

Now create the [Column] and [Row] placeholder calculations.

// Column
([Index] - 1) % [Total Columns]
// Row
(([Index] - 1) - [Column]) / [Total Columns])

For this example we’ll plot [Sub-Category]. Add [Sub-Category] and [Index] to detail. Place [Column] on columns and [Row] on rows. Make sure [Column] and [Row] are discrete dimensions. Edit the table calculations and select [Sub-Category].

From here you can make whatever visualizations you want. But for this example we’ll show sales by quarter.

Step 2: Build the Visualization

Add Quarter of Order Date to columns. Add year of Order Date to color and SUM(Sales) to rows. You will eventually replace SUM(Sales) with a different calculation.

Step 3: Add Labels Above the Bars

To add labels we need to create a calculation that will center a label above the bars. You can do this with a calculation called [Order Date | Trellis Label].

// Order Date | Trellis Label
{MIN([Order Date])} + (({MAX([Order Date])} - {MIN([Order Date])})/2)

Add this calculation to the right of the quarter of order date calculation. Change this mark type to text. Create an additional calculation called [Bars + Label]. This calculation will “dynamically” create the appropriate aggregation based on the number of marks in a cell.

// Bars + Label
IF SIZE() > 1 
THEN SUM([Sales]) 
ELSE 1.1 * AVG({
        MAX(
            {FIXED [Sub-Category], DATETRUNC("quarter", [Order Date]) : 
             SUM([Sales])
        })
      }) 
END

Replace SUM(Sales) with [Bars + Label]. Edit the table calculation of [Bars + Label] so labels are even across the top.

Add [Sub-Category], [Index] and SUM(Sales) to text on the text marks card. Sort [Sub-Category] descending by sum of sales.

Step 4: Format

I’ve added year to color on bars, but removed year from color on the text marks card. Then I formatted the bars. Finally I added max labels.

Like what you are reading?

Get articles sent to you when they are posted.
Comments are closed.