Tableau bins are used to divide your data into groups of equal size when displayed in a chart.
You can think of bins as containers that hold a specific range of values from the discrete or continuous variable you use to create the bins.
Any kind of data grouping in the Tableau view can be considered as a set of bins.
In the graph below, the
City field can be considered as bins that divide the
Total Sales sum value:
When you create bins from a variable in your dataset, the bins will divide your variable values into groups. It’s like how the
City variable divides the
Total Sales values above.
Let’s learn how to create bins for a field in Tableau with this tutorial
You can download the dataset used for this tutorial here:
The dataset contains fictional sales data of an office supplies company. You can load it into Tableau as a Text File.
Open the sheet view, then right-click on the
Total Sales variable and select Create > Bins…
as shown below:
An Edit Bins window will pop up, allowing you to set the options for the bins field as follows:
The most important value in the window is the Size of bins value. That value will be used to divide your field later.
Tableau can also suggest the optimal bin size for your bins field when you click on the Suggest Bin Size button.
Here’s the formula Tableau use to calculate the optimal bin size:
Number of Bins = 3 + log2(n) * log(n)
n variable is the number of distinct rows in the field. Tableau determines the size of the bins by dividing the difference (
Diff) between the minimum (
Min) and the maximum (
Max) values BY the
Number of Bins.
You can calculate it yourself by looking at the Range of Values fields in the lower part of the Edit Bins window:
Difffield shows the difference between the
CntDfield is the number of distinct rows in the field
Using these values, you can perform the calculation as follows:
# Number of bins 3 + log2(48) * log(48) = 12.38 # Size of bins (diff / number of bins) 1862 / 12.38 = 150.4
The bin size from the calculation above is rounded down to
150, so that is the bin size that Tableau recommends.
Once you’re done, click on the OK button and you’ll see the
Total Sales(bin) variable available as a discrete variable.
Create a new sheet and do the following steps:
- Drag the
Total Sales(bin)into the Columns shelf
- Drag the
Total Salesmeasure into the Rows shelf
- Right-click on the
SUM(Total Sales)variable and change the Measure from Sum to Count
You’ll see the
Total Sales value count on the size of the bins as shown below:
Based on the result, you can see that the
Total Sales variable has no value between 1350 to 1500 and 1650 to 1800 as they are empty.
A bins field can be created whenever you need to group your variable using an arbitrary range relevant to your project.
You can view and download the workbook for this tutorial here:
Now you’ve learned how Tableau bins work. Great job! 👍