Last Modified Date: 24 Aug 2022
Environment
- Tableau Desktop
Resolution
The directions for each example start from the corresponding "original" worksheet in the example workbook that can be downloaded from the right-hand pane of this article.Option 1: Convert the discrete field to a continuous numeric or date field
- Select Analysis > Create Calculated Field
- In the Calculated Field dialog box that opens, do the following, and then click OK:
- Name the calculated field. In this example, the calculated field is named "Sales Bins"
- In the formula field, create a calculation similar to the following:
(FLOOR([Sales]/1655)*1655)
Note: The above calculation is the same calculation that Tableau Desktop uses to generate bins. 1655 is the size of the bin.
- Right-click [Sales Bins] in the data pane and select Convert to Dimension
- Right-click [Sales Bins] in the data pane and select Convert to Continuous
- Replace [Sales (bins)] with [Sales Bins] on the Columns shelf
- On the Marks card, change the mark type from Automatic to Bar in the dropdown menu
- Add a reference line to the Sales Bin x-axis as normal. For detailed directions, see Reference Lines, Bands, Distributions, and Boxes
Option 2: Use a calculated field as a dual axis to mimic a reference line
- Select Analysis > Create Calculated Field
- In the Calculated Field dialog box that opens, do the following, and then click OK:
- Name the calculated field. In this example, the calculated field is named "Mock Reference Line"
- In the formula field, create a calculation similar to the following:
IF [Sub-Category]= "Chairs & Chairmats" OR [Sub-Category]= "Rubber Bands" THEN 1 END
- Drag [Mock Reference Line] to the Rows shelf.
- On the SUM(Mock... Marks card, do the following:
- Change the mark type to Bar in the dropdown.
- Click Size and adjust the width of the bars with the slider.
- Right-click the [Mock Reference Line] y-axis in the view and select Edit Axis...
- In the Edit Axis dialog, do the following and close the dialog:
- For Range, select Fixed
- Set the range from 0 to 1
- Right-click [Mock Reference Line] on the Rows shelf and check Dual Axis.
- Right-click [Mock Reference Line] on the Rows shelf and uncheck Show Header.
Cause
The ability to add a reference line to a discrete field is not currently available in Tableau Desktop.Additional Information
See the attached example workbook for a variation of Option 1 using dates.Thank you for providing your feedback on the effectiveness of the article.
Open new Case
Continue Searching
Knowledge Base
Community
Product Help
Training and Tutorials