*{This is the second blog post in the #TableauStatsMonth series, and is a guest post by Tableau Public author Jim Wahl. View this post as a viz, or read the text version below the viz.}*

Sparklines—the word-sized line graphs—have become a standard dashboard element. In Stephen Few’s *Information Dashboard Design*, all but one of his recommended dashboards use sparklines to display time series data for key metrics or members of a dimension. Not only do sparklines provide a lot of information in a small space, they look great. What’s not to like?

Using just a portion of my iPhone’s screen, I can show the last quarter’s weekly sales data of a chain store’s furniture sales. It appears that the Eastern region might deserve a congratulatory call for ending the quarter strongly. Or did they?

A regular line graph shows the East’s sales have been remarkably stable, and overall sales were not affected by their “surge” in the last week.

**Aphophenia**

This is the sparkline dilemma: too little context and it’s possible to see patterns or trends that aren’t; too much context and the sparklines are no longer compact and elegant. Statistical techniques can show the significance of changes in time series data, but two visual techniques might be easier and work just as well. First, you could add high and low values. Second, consider Few’s bandlines, which are now easier to implement with Tableau 8.1’s percentile function.

**Elegant High and Low Labels**

It’s tempting to use Tableau’s one-click label feature for min/max points, but these labels can get clobbered by the line in sparkline-sized graphs. Another option is to add a parallel worksheet with columns for the high and low values.

My favorite approach uses labels on invisible reference lines to position the high and low values vertically next to the line. If normal reference lines take a couple of minutes to produce in Tableau, these enhanced sparklines take maybe five minutes.

First add the high and low values by:

- Right-clicking the vertical axis > Add Reference Line and select Line per Pane for the maximum value. Choose Value for the Label and None for Formatting.
- Next, right-click the reference line in the graph, select Format, and change Alignment to right-justified, centered vertically.
- Repeat this for the minimum value.

Next, make room for the labels by extending the horizontal date axis with another invisible reference line placed a few weeks beyond the max date. Below I added five weeks:

**Extended Axis** = DATEPART(‘week’, WINDOW_MAX(MAX([Date]))) + 5

Right-click this new field, convert it to continuous, and drag it to the Detail button. Now you can add a reference line on the horizontal axis with this field and None for the label and line format.

I also like to highlight the high and low values on the line graph with circles. You can do this with another calculated field:

**High-Low Points** = IF WINDOW_MAX(SUM(Sales)) == SUM(Sales) OR

WINDOW_MIN(SUM(Sales)) == SUM(Sales)

THEN SUM(Sales) END

Drag this field to the right axis, right-click the axis, and select Synchronize Axis. On the Marks shelf, select All and remove Measure Names from Colors; then select the **High-Low Points** card and change the mark type to Circle and color to blue.

**Bandlines**

Bandlines attempt to solve the context problem by adding horizontal bands for each quartile: basically they’re a cross between a sparkline and a boxplot. (Few developed bandlines and describes them here.)

Tableau 8.1’s percentile function simplifies bandline implementation. Still, they require intermediate, if not Jedi-level, table calc skills, because the bands should be calculated across all of the dimensions—in this case Category, Region, and Date—to facilitate comparison. In our example, the top-performing Central region has many weeks in the upper quartile, while the South had a few bleak weeks.

The basic trick is to use two sets of table calcs to find the maximums at different levels of detail. The first determines the overall percentile, for example: 75th Percentile Table = WINDOW_PERCENTILE(SUM(Sales), 0.75) with Compute Using set to Table Across then Down (Date then Category and Region).

The second table calculation—WINDOW_MAX(SUM(Sales)) set to Compute Using Table Across—finds the max sales for each region pane and determines whether or not to place any particular reference band. In the Eastern region, for example, the max sales were $5,021, which is below the 75th percentile of $6,840. In this case we don’t want to place the 75th percentile reference band, because it will extend the vertical axis and flatten the sparkline.

Determining whether to place the line requires some additional logic, and the attached workbook has more detailed notes on the procedure I used. And if you’re new to table calcs, the bandline worksheet is a nice example of nested table calculations with different levels of aggregation.

**Visual Statistics**

Statisticians may cringe at the thought of using context instead of computation to determine significance, but it’s an important intermediate step and one that’s often easy to implement. Certainly a little subtle context can’t hurt. In any case, whenever you use sparklines, remember Edward Tufte’s guidance and ask yourself: Do the prominent visual effects convey relevant information?

## コメント

## Context always helpful and

Context always helpful and let us get more insight s from original chart

## The text description for

The text description for extending the axis does not appear to match the technique as applied in the workbook. The text of this posts talks about creating an [Extended Axis] field with a WINDOW_MAX function, while the workbook does not use the WINDOW_MAX function, but adds in a measure calculation to the field after it is added to the detail pill. Additionally, it is not necessary to convert the the [Extended Axis] detail pill to continuous, but it _is_ necessary to convert the [Date] pill on the columns shelf to continuous and to set the date to use the week number level. Only after completing this conversion will the MAX[Extneded Axis] field be available for adding as a reference line to the horizontal axis.

There may be additional errors, but that's all I was able to get through after spending an hour puzzling through why both Tableau 8.1 and 8.0 weren't working per the instructions.

David

## I agree with Wendy, use the

I agree with Wendy, use the original charts with the correct minimal context as espoused by Stephen Few, but always ensure you are giving sufficient context information so as not to be ambiguous or misleading just for the sake of using a snazzy graphic.

## Hi David, Sorry you had

Hi David,

Sorry you had trouble recreating this example in Tableau 8.0.

Both formulas for extending the x-axis should work:

Extended Axis = DATEPART('week', WINDOW_MAX(MAX([Order Date]))) + 5

or

Extended Axis = DATEPART('week', [Order Date]) + 5

The second formula is a bit simpler, and is what I used in the video tutorial in the second tab of the workbook.

In both cases the scope is important. For the table calc you want to cover all of the dimensions in the view, and Compute Using should be set to Table (Across then Down). For the second formula, you should set the scope to Table in the reference line dialog box. The table calc formula could also be optimized by wrapping it in a PREVIOUS_VALUE() function so that it is only computed once.

Also in both cases, the measures need to be continuous, green pills when added to the Detail button. And, as you point out, the Date pill on the Columns / x-axis shelf needs to be continuous to get the Add Reference Line option when right-clicking the axis.

There are other ways to solve this problem and variations that may need different solutions. For example, if you always display a full year, you could simply use a fixed range axis.

Anyone else having difficulty, please shoot me an email (jim@broadbandmetrics.com) or post a question in the community forums.

Jim