# Build Better Sparklines in Tableau

So you want to add some spice to your bland looking Sparklines in Tableau? You have come to the right place (start by watching the video above). Let’s talk about how a Sparkline is defined per Wikipedia:

“A sparkline is a very small line chart, typically drawn without axes or coordinates. It presents the general shape of the variation (typically over time) in some measurement, such as temperature or stock market price, in a simple and highly condensed way. Sparklines are small enough to be embedded in text, or several sparklines may be grouped together as elements of a small multiple. Whereas the typical chart is designed to show as much data as possible, and is set off from the flow of text, sparklines are intended to be succinct, memorable, and located where they are discussed.”

Here are a few examples of Tableau specific sparklines in action (with latest complete month bubble indicators and reference lines): Notice how I do not include any data axes, but you can clearly recognize the data trends in the visuals.

Here is an example of how I used the sparklines demonstrated in the video to build a out a classic yet refined looking Tableau dashboard.

For reference purposes I am going to list three formulas used in the completion of the sparklines, you’ll have to watch the video to learn how to put them together.

In this exercise I am using that standard Tableau Superstore data set which you can perform a Google search to find if you are using Tableau Public.

Calculated Fields

Calculated Field #1 (Name: SPRK_CircleMonths)

This calculated field puts a circle on the penultimate month data points. Penultimate is just a fancy SAT word way of saying “next to last”. When the month of the data point on the line chart (Order Date) equals the next to last order date month in the dataset, then return the Order Date.

``````//IF THE MONTH OF THE DATE ON THE LINE CHART EQUALS THE MONTH-1 OF THE MAXIMUM DATA POINT
// THEN RETURN THE DATE
If DATEPART('month',[Order Date]) = DATEPART('month',dateadd('month',-1,{MAX([Order Date])}))
Then [Order Date] END``````

Calculated Field #2 (Name: SPRK_CircleMonths)

This logic will be applied to the circles generated by the previous calculation SPRK_CircleMonths. Only the next to last month will meet the TRUE condition (which will be colored as red).

``````// IS THE MONTH OF THE CHART DATE EQUAL TO THE MOST RECENT DATE MONTH MINUS 1 MONTH
// E.G., NOV 2018 = NOV 2020 WILL RESOLVE TO TRUE DUE TO MATCHING MONTHS
``````

Calculated Field #3 (Name: SPRK_RefLine Profit)

This logic will return the profit associated with the next to last month in the dataset to display on the reference line.

``````// RETURNS A VALUE USED FOR THE REFERENCE LINE
// IF THE MONTH OF THE DATE = THE MONTH OF THE MAXIMUM DATE MINUS 1 MONTH (GET A COMPLETE FIRST MONTH)
if DATETRUNC('month',[Order Date])