Discretizing data

Sometimes we require discretizing (or binning) of numeric data for pretty labeling or meeting some format guidelines; for example, you may need to report the sales amount in thousands, and thus you will need to create a field that will put every sales amount in various bins, for example, 0-1000, 1000-2000, and so on.

Getting ready

Let's use the sample file Sample – Coffee Chain (Access). Open a new worksheet and select Sample – Coffee Chain (Access) as the data source.

How to do it...

Once the data is loaded on the worksheet, perform the following steps to discretize a numeric value or create bins:

  1. Right-click on Sales from Measures and select the Create Bins option.
  2. Hit the Load button to see the distribution of the Sales amount.
  3. In the Size of bins box, enter 200, as shown in the following screenshot, and hit OK:
    How to do it...
  4. Drag-and-drop Sales (bin) from Dimensions in the Rows shelf.
  5. Drag-and-drop Product Type from Dimensions in the Columns shelf.
  6. Drag-and-drop Market from Dimensions in the Rows shelf, but place it before Sales (bin).
  7. Drag-and-drop Number of Records from Measures in the Text box under the Marks pane to create a table similar to the one shown in the following screenshot:
    How to do it...

How it works...

When we hit the Load button on the Create Bins [Sales] dialog box, Tableau loads the distribution; that is, minimum, maximum, and the difference between the minimum and maximum value of the underlying measure. By looking at those values, we can decide the appropriate number of bins. Once we enter the number of bins, Tableau puts all the individual values of the underlying measure into bins, which start with zero and end with the highest possible value of the range that doesn't exceed the maximum value. For this recipe, we had the maximum value of 895 dollars and the maximum value of the bins was 800 dollars, because the next bin value would be 1,000 dollars and there are no values that are over 1,000 dollars.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset