# How to Make a Gauge Chart in Tableau

In this blog post, I will show you how to create a gauge chart that is extremely customizable, adjustable to your data, and can fit several different scenarios. The final result will allow you to make stylistic changes with a click of a button.

## What is a Gauge Chart?

A gauge chart displays the performance of a metric relative to scale using a needle on a dial. Often used on executive dashboards, gauges use the direction of the needle and the color of the dial to help users quickly understand performance.

## When Should I Use a Gauge Chart?

A gauge chart is most effective when paired with other gauge charts. This will allow your end-users to better understand the context of current performance relative to expectations. Before we get started–if you are looking for a simple gauge chart, there are plenty of resources already available, including some of our previous solutions, the Flerlege Twins.

The goal of this solution was to create a gauge chart without images that also looked aesthetically pleasing. This blog post will outline the steps for creating the chart. If you want to skip the tutorial and go straight to a template, you can go here.

If you are staying for the tutorial, I’d recommend you read the following tutorial, as we’ll utilize map layers for this gauge.

## Step 1: Make the Dial

To build the gauge, we will create a separate data source. Don’t worry; this data source will work easily with any other data source. The data source has two columns– one column called [value] that counts from 0 to 401 and repeats five times. The second column is called [level], where the numbers in the column range from 1 to 5. This column covers each of the five iterations of the numbers in the [value] column. You can get the data here.

After you have downloaded this data source, connect to the data source in Tableau and make an extract.

On a new sheet, we are going to create five Float parameters. These parameters will help us size the dial on the gauge.

Let’s call the first three [Level 1], [Level 2], and [Level 3]. All three parameters use a range between 0 and 1 with a step size of 0.01. Set the values of [Level 1], [Level 2], and [Level 3] to .4, .6, and .8, respectively. Create a 4th parameter called [Over Target]. This will also be a Float parameter, but this time the range will be between 1 and 1.5 with a step of 0.01. Set the value to 1.1. The final parameter will be called [size], and it will help us establish the width of the band on the dial. Set the range between 0 and 1. Set the value to .2.

Now that we have created these parameters, let’s create the calculations that will build our dial. This chart will rely on polar coordinates, so it’ll be a throwback geometry class for some. This means we first need to specify the radius and the degrees of the dial.

To do this, we are going to create four total calculations. First, let’s calculate how far each part of the dial will arc. Create a calculation called [Depth] and type the following:

```				```
// Depth
CASE [Level]
WHEN 1 THEN [Level 1]
WHEN 2 THEN [Level 2]
WHEN 3 THEN [Level 3]
WHEN 4 THEN 1
WHEN 5 THEN [Over Target]
END
```
```

Here we are assigning how far each arc should go.

Next, let’s calculate the [Dial Degrees].

```				```
// Dial Degrees
PI()*(IF [Value] <= 200
THEN [Value]/200
ELSEIF [Value] <= 401
THEN (200 - ([Value] - 201))/200
END)*([Depth]/[Over Target])

```
```

```				```
// Dial Degrees
IF [Value] <= 200
THEN 1
ELSEIF [Value] <= 401
THEN 1 - [size]
END
```
```

With [Dial Degrees] and [Dial Radius] we can then create a map layer called [Dial] that will create the dial for us.

```				```
// Dial
MAKEPOINT(
)

```
```

Now that you have [Dial] created, Place this map layer onto the visualization this should add [Longitude (generated)] and [Latitude (generated)] to the Columns and Rows shelves. Add [Level] as a discrete dimension to the color. Change the mark type to polygon, then click-and-drag [Value] onto the path as a continuous dimension. Turn off your tooltips. The result will be the dial to a gauge.

## Step 2: Make the Ticks

Now that we have the dial, let’s make the ticks. For this, we will use the same data source we’ve used for the dial.

First, create a float parameter called [Tick Length]. This will determine the length of the ticks. Use a range between .01 and .15 with steps of .01. Set the value to .05.

We’ll need to create 3 calculations: [Tick Degrees], [Tick Radius], and [Ticks].

```				```
// Tick Degrees
IF [Value] IN(0, 1, 2, 3, 4, 5)
AND [Level] = 1
THEN 1 - [size] - .05 - [Tick Length]
ELSEIF [Value]  IN(6, 7, 8, 9, 10, 11)
AND [Level] = 1
THEN 1 - [size] - .05
END
```
```
```				```
CASE [Value]
WHEN IN(0, 6) THEN 0
WHEN IN(1, 7) THEN [Level 1]
WHEN IN(2, 8) THEN [Level 2]
WHEN IN(3, 9) THEN [Level 3]
WHEN IN(4, 10) THEN [Over Target]
WHEN IN(5, 11) THEN 1
END * PI()/[Over Target]
```
```
```				```
// Ticks
MAKEPOINT(
)

```
```

Once you have created [Ticks], click-and-drag this calculation over to the existing sheet and add the calculation as an additional map layer. After adding the map layer, change the mark type to Line. Add [Tick Degrees] to detail as a continuous dimension. Add Value to the path as a continuous dimension, then set the size to the smallest value possible. One item not discussed up until now is what [Level 1], [Level 2], [Level 3], and [Over Target] provide to the visual. If you update the values in these parameters, it will change how the dial is colored. In general, you will want [Level 1] < [Level 2] < [Level 3] < 1 < [Over Target]. If you update, you will see how the color is adjusted on the dial.

If you also adjust the size, you will see how that value increases or decreases the band size of the dial.

So far, we’ve created a gauge chart that can be applied to any data source. For the next part, we will connect to a data source and build the gauge chart.

## Step 3: Make the Pointer

For this example, we will connect to the Sample – Superstore data source. As you build your data source, you will create a logical join (relationship) between your data source and a second data source you will need to build.

Using your tool of choice, create a CSV with a single column called Point that counts up from 1 to 20. Name this data source “placeholder.csv”. Then create an additional connection to the data source. Create a logical join between Sample – Superstore and placeholder.csv. Create calculated joins and set the value of each side of the join to 1. This will create a many-to-many relationship but won’t affect any of the work we’ll do.

Once again, we need to calculate the radius and degrees then create a map layer. We will utilize the join that we created to build the calculations. You need to build these calculations using the data source containing your key metrics. For this example, it is Sample – Superstore.

But before we build the calculations, we need to set a target. For this example, we will code a sales target in a float parameter called [Target]. Let’s set the target to 2,000,000.

We also need to define a key metric. This is the value we are going to compare to the target. For this example, I am going to use total sales. In a new calculated field called [Key Metric], let’s create that total.

```				```
// Key Metric
SUM([Sales])

```
```

Now, let’s calculate the degrees of the pointer. Create a calculated field called [Point Degrees] and type the following:

```				```
// Point Degrees
CASE [Point]
WHEN 1 THEN 0
WHEN 2 THEN MIN({[Key Metric]}/[Target]/[Over Target],1)
END * PI()

```
```

With this calculation, you are defining values to the first to rows of the placeholder.csv data source. For Point 1, the pointer is centered at 0. For Point 2, the value is defined at a percent relative to the target. If that target goes over the maximum value, it will just put the arrow all the way to the top of the gauge.

Next, let’s calculate the [Point Radius]:

```				```
CASE [Point]
WHEN 1 THEN 0
WHEN 2 THEN 1 - [size]/2
END
```
```

This will put the point in the middle of the dial.

Now let’s create the map layer. Call it [Gauge Point].

```				```
// Gauge Point
MAKEPOINT(
)

```
```

Take the [Gauge Point] calculation and add the map layer to the visualization on the sheet. Thanks to map layers, you can add multiple data sources to the same map in Tableau without performing a blend.

Rename the layer to Point. Change the mark type to the line. Add [Point] as a continuous dimension to the path.

Create a new calculation called [Point Size]:

```				```
// Point Size
CASE [Point]
WHEN 1 THEN 10
WHEN 2 THEN .2
END

```
```

Add point size to size. Adjust the size to your liking for the pointer. Change the color to black. Your gauge is now functional, but it still needs labels.

## Step 4: Add the Labels

To add the labels, we once again need to calculate the degrees and radius of these points–then we can add labels.

Create a float parameter called [label padding]. This will provide spacing between the end of the tick and the labels. Set the value to 0.1. The benefit to using a parameter for this is that as you resize your gauge, you can quickly update the parameter to add spacing accordingly.

Add a calculation for [Labels Degrees] and [Labels Radius] to the Sample – Superstore dataset.

```				```
// Label Degrees
CASE [Point]
WHEN 1 THEN [Level 1]
WHEN 2 THEN [Level 2]
WHEN 3 THEN [Level 3]
WHEN 4 THEN 1
WHEN 5 THEN [Over Target]
WHEN 6 THEN 0
END * PI()/[Over Target]

```
```
```				```
CASE [Point]
WHEN IN(1, 2, 3, 4, 5, 6) THEN 1 - [size] - .05 - [Tick Length] - [label padding]
END

```
```

Use these two calculations to build a map layer called [Labels]:

```				```
// Labels
MAKEPOINT(
)
```
```

If you notice very closely, there is an additional -.05 in the make point calculation. That is to adjust the left-right because the text is typically wider than it is tall.

Add the [Labels] map layer to the visualization. Change the layer name to Labels. Change the mark type to text. Add [Point] as a continuous dimension to detail.

Create a new calculation called [Labels Key Metric] that will be used for the labels:

```				```
// Labels Key Metric
CASE [Point]
WHEN 1 THEN [Level 1]
WHEN 2 THEN [Level 2]
WHEN 3 THEN [Level 3]
WHEN 4 THEN 1
WHEN 5 THEN [Over Target]
WHEN 6 THEN 0
END * [Target]

```
```

This calculation leverages the parameters used for the gauge size as well as the target to create the labels automatically. We are almost complete with the build. The last part is adding labels, including the actual values and the target to the gauge.

First, let’s add a title. Create a calculation called [KPI Name].

```				```
// KPI Name
MAKEPOINT(1.1, 0)

```
```

Add [KPI Name] as another map layer. Change the layer name to Title. Change the mark type to text. Create a new text parameter called [KPI Name], Set the value to Sales. Edit the text so the title is larger than the tick labels. For this example, I’ll set the value to size 11 font.

Now let’s add labels for the key metrics. Create a calculation called [KPI].

```				```
// KPI
MAKEPOINT(-.2, 0)
```
```

Add this calculation as another map layer. Keep the layer name the same. Change the mark type to text. Add [Key Metric] and [Target] to text. Edit and format the text to your preference. This will result in the following: ## Step 6: Finalize Your Visualization

In the last step, you have to do some minor clean-up. First, take the “Point” map layer, click and drag the layer above the “Labels” map layer. You are doing this so the gauge sits above the labels on the visualization.

Next, change the colors on the dials. This will make the chart easier to interpret.

After that, set the background maps to none. You can do this by going to Maps on the top menu, then going to the Background Maps, and then selecting None. This will turn off lots of the mapping and open up some additional formatting. After this step, your chart might look like this: First, edit your axes. Set your longitude to be between -1.1 and 1.1. Set your latitude axis to be between -0.4 and 1.2. Then hide these axes.

Next, hide all rulers, lines, ticks, and dividers on the sheet.

For the last step, click on color on the “Dial” layer and set the border to white. This will complete the build of your gauge. All you need to do is add it to your dashboard somewhere. As you add it to a dashboard, remember the ideal ratio is eight units tall for every 11 units wide. This will keep the gauge looking circular in nature. ## Conclusion

The goal of this tutorial was to create a gauge chart that is worthy of placing on any dashboard. On top of that, I wanted to make it extremely customizable by using map layers and parameters. With map layers, you can turn on or off any part of the gauge chart. With parameters, you can quickly change the size of almost any component to display the information of interest.

If you want to short-cut the development of the gauges, you can always download our gauge template.

Do you have more questions about Tableau? Reach out to our team of experts!

## Accelerate and automate your data projects with the phData Toolkit

Introducing Data Coach is our premium analytics training program with one-on-one coaching from renowned experts.  Data Coach is our premium analytics training program with one-on-one coaching from renowned experts. 