Five Different Ways to Add Reference Lines

by Ali Agah

One of the best ways to tell users what certain numbers mean is to add context to your chart. One of easiest ways to add context? Reference lines!

I've found five ways we can add them to our charts...

1) The Analytics Tab

Perhaps the most popular method is to open the Analytics Tab and drag the reference line into the desired axis and level.

fig1. Using the analytics tab

2) Right Click on the Axis

Right clicking on the axis you want to add a reference line to presents an Add Reference Line option. Click it for the same option as the method above.

Fig2. Right clicking the axis


3) Edit another Analytics item

If you already have analytics items in the view you can right click on the item, click edit and select 'Line' within the editing window (see fig3 below).

This is the indecisive person's favourite method. Tableau updates the reference items in real time as you edit and it remembers your configurations for each type until you click the OK. So you can experiment till your heart's content.

Fig3. Line option in the 'Edit Reference Line, Band, or Box' menu window

4) Table Calculations

This involves writing the table calculation and adding it to the view. If you have a line chart, you can drop it on the same axis, but a more flexible option is to create a dual axis. Two methods in one!

Fig4. Using a table calculation to make a line chart

The obvious difference to a 'real' reference line is that the line is disconnected from from the borders/axis. Isn't it beautiful?

Yet, the real beauty of this method is the ease and extent of formatting. As a line chart, this type of reference line benefits from having all the features of a chart! Such as:

1) ability to be placed behind or in front of the main chart;

2) easy access to formatting options;

3) more flexible labelling.

You may be concerned that this limits you to only one reference line per chart but that's not true. Create a shared axis for your reference lines! (see Fig4.1 below).

Unfortunately, you can only label values though.

Fig4.1. Multiple reference lines using a shared axis

Tip: writing table calculations

The easiest way to write the table calculation is to add a reference line to the view and use the editing window to figure out the calculation. Simply write the calculation as shown in Fig.4.2.

Fig4.2. Using the menu to write a table calculation


5)  Use Parameters for dynamic reference lines

Some may argue this is just an extension of the above but I beg to differ (slightly).

Method 4 creates static reference lines. If you want multiple reference lines you end up with a crowded chart; plus the inflexibility of labelling may lead to confusion.

That's why I recommend creating a dynamic reference line using a parameter. See how the label changes?

Fig5. Dynamic reference line in action

How to

1) Create a parameter with your calculation options as string values

2) Write a CASE statement for the values

Fig5.1. Calculation for the reference line

4) Add the reference line as we did in Method 4

5) Place the parameter in the labels shelf and confiture the labels as you like

Did I miss anything?

If you know of another method which I didn't mention let me know! Twitter or email would be best.

Enjoy vizzing!

Fri 07 May 2021

Fri 04 Jun 2021