Automatic Bins and Beeswarms in Tableau

Ok, quick and dirty how to (mostly because I'm copying a lot of this from a old post I put on the Forums).


Setting up the Automatic Bins

Tableau suggests the Optimal Bin Size by performing the following Calculation on the dataset.

( MAX([Measure Value]) - MIN([Measure Value]) )
/
3 + LOG(COUNTD([Measure Value], 2) * LOG(COUNTD([Measure Value]))

Click here for additional details Create Discrete Bins from a Continuous Measure

But Tableau also Rounds the Bin Size to the nearest Base 10, so $1,864 will Round to $2,000.

So I thought, why not create this record level with LoDs so that I can use Bins in an LoD.

Calculations

[MAX Sales] => INT(MAX([Sales]))
[MIN Sales] => INT(MIN([Sales]))

[Difference in Max/Min Sales] => [MAX Sales]  - [MIN Sales]

[Number of Bins] => INT(3 + LOG(COUNTD([Sales]), 2) * LOG(COUNTD([Sales])))

[Optimal Bin Size] =>

INT({
    FLOOR(INT([Difference Max and Min Sales] / [Number of Bins] )
          /
     POWER(10, FLOOR(LOG(INT([Difference Max and Min Sales] / [Number of Bins] )))))
*
POWER(10, FLOOR(LOG(INT([Difference Max and Min Sales] / [Number of Bins] ))))})

[Sales (Bin)] =>

FLOOR([Sales] / [Optimal Bin Size]) * [Optimal Bin Size]

WHY DO THIS INSTEAD OF JUST USING A NORMAL BIN? Because with one slight adjustment, we can change the level the BINS are calculating, without needing to re-create the bins as new data pours in.

INT({ FIXED [Sub-Category] :
    FLOOR(INT([Difference Max and Min Sales] / [Number of Bins] ) / POWER(10, FLOOR(LOG(INT([Difference Max and Min Sales] / [Number of Bins] )))))
    *
    POWER(10, FLOOR(LOG(INT([Difference Max and Min Sales] / [Number of Bins] ))))})

Now our Bins will automatically adjust to the Sub-Category (or whatever level you set it to).

The Beeswarm Calcs

Once we have our Automatic Bins, we need to setup the Calcs for the Beeswarm. This is pretty simple, we just need to create an X calculation to equally spread out values left and right.

[BeeswarmX] =>

IF INDEX()%2 = 0 THEN INDEX()-1 ELSE -INDEX()+1 END

Place this on the Columns Shelf, Min Sales on the Row Shelf, Order ID and Sales Bins on the Detail Shelf.


Now, we have to configure our BeeswarmX so that we can spreadout out of values.

To do this, we set the Calc to Compute using Order ID and Sales Bins, Restart every Sales Bins and do a Custom Sort on Order ID for Sales Ascending.


And that's it! It takes some calcs to setup, but it gives you a nice automatic distribution of your Dataset. 


Previous
Next Post »
0 Comment