KNOWLEDGE BASE

## Add Box Plot Labels

Published: 19 Jul 2018
Last Modified Date: 04 Aug 2020

### Question

How to add labels for box plot values, such as upper hinge or median.

### Environment

• Tableau Desktop

### Answer

The attached example workbook uses the sample data set Superstore to demonstrate the following directions:

Step 1: Create Calculations
1. Select Analysis > Create Calculated Field.
2. In the Calculated Field dialog box that opens, do the following:
• Name the calculated field. In this example, the calculated field is named Lower Hinge
• In the formula field, create a calculation similar to the following:
```WINDOW_MEDIAN( SUM([Sales]),
FIRST(),
INT((WINDOW_COUNT(MIN([Order ID]))+1)/2) - INDEX()
)
```
• Click OK.
3.  Create a calculated field with a name like Upper Hinge with a calculation similar to the following:
```WINDOW_MEDIAN( SUM([Sales]),
INT(ROUND((WINDOW_COUNT(MIN([Order ID]))+1)/2,0)) - INDEX(),
LAST()
)
```
4. Create a calculated field with a name like Upper Whisker with a calculation similar to the following:
```WINDOW_MAX(
IF SUM([Sales]) < [Upper Hinge] + 1.5*([Upper Hinge]-[Lower Hinge])
OR SUM([Sales]) = [Upper Hinge]
THEN SUM([Sales])
END
)
```
5. Create a calculated field with a name like Lower Whisker with a calculation similar to the following:
```WINDOW_MIN(
IF SUM([Sales]) > [Lower Hinge] - 1.5*([Upper Hinge]-[Lower Hinge])
OR SUM([Sales]) = [Lower Hinge]
THEN SUM([Sales])
END
)      ```
6. Drag Lower Hinge, Upper Hinge, Lower Whisker, and Upper Whisker onto Detail on the Marks card

Step 2: Set the Compute Using Settings
There are two sets of instructions here depending on how the data is structured. The first method is simpler, but will only work if the field(s) defining each circle in the view does not have the same value in more than one box plot.

Method 1:
1. Right-click Order ID on the Marks card and select Sort
2. In the Sort dialog, do the following:
• For Sort Order, select Ascending
• For Sort By, select Field
• In the dropdowns, select Approval Time (BD) Per Request Value and Average
• Click OK
3. Right-click Lower Hinge on the Marks card and select Compute Using > Order ID
4. Repeat step 3 for all Upper Hinge, Lower Whisker, and Upper Whisker
Method 2:
1. Right-click Lower Hinge on the Marks card and select Edit Table Calculation
2. In the Table Calculation dialog, do the following:
• For Compute Using, select Specific Dimensions
• Check all dimensions in the list of dimensions
• Move Sub-Category to the top of the list of dimensions
• For At the level, select Deepest
• For Restarting every, select Sub-Category
• Click Automatic Sort to open the sort dropdown
• Select the Custom radio button
• In the dropdowns select Sales, Sum
• Select the Ascending radio button
3. Repeat steps 1-2 for Upper Hinge
4. Right-click Lower Whisker on the Marks card and select Edit Table Calculation
5. In the Table Calculation dialog, do the following:
• In the dropdown under Nested Calculations, select Lower Hinge
• Repeat all sub steps from 2
• In the dropdown under Nested Calculations, select Upper Hinge
• Repeat all sub steps from 2
• In the dropdown under Nested Calculations, select Lower Whisker
• Check all dimensions in the list of dimensions
• Check only Order ID
6. Repeat steps 3-4 for Upper Whisker
Step 3: Add the Labels
1. Right-click the Sales axis in the view and select Add Reference Line
2. In the Add Reference Line, Band, or Box dialog, do the following:
• Select Line
• For Scope, select Per Cell
• For Value, select SUM(Sales), Median
• For Label, select Value
• For Line, select None
• Click OK
3. Repeat steps 1-2 for Lower Hinge, Upper Hinge, Lower Whisker, and Upper Whisker, using the calculation in place of SUM(Sales)

### Additional Information

• SUM(Sales) should be replaced with the measure and aggregation used in the box plot view
• Order ID should be replaced with the field(s) used to create each circle in the view
• If the view is disaggregated, then convert Sales to a dimension and use Sales in place of Order ID
• Sub-category should be replaced with the field(s) used to create each box plot
• If the view contains more than two dimensions then it will be necessary to customize how the table calculation is computed. The exact solution will vary, but typically the solution will be to check any dimensions, which are on the Columns shelf, in the Table Calculation dialog, and leave all other dimensions unchecked
• Tableau uses Tukey inclusionary hinges. For a detailed explanation of how Tukey inclusionary hinges are calculated, please see How to do Box Plot Calculations in Tableau

Discuss this article...
Did this article resolve the issue?