KNOWLEDGE BASE

Creating Error Bars or CI Bars


Published: 22 Apr 2014
Last Modified Date: 05 Oct 2018

Question

How to create error bars or confidence interval (CI) bars in Tableau Desktop.

Environment

Tableau Desktop

Answer

The following instructions can be reviewed in the attached workbook.

Build the View

  1. Right-click and drag [Sales] to the Rows shelf.
  2. In the Drop Field menu, select AVG(Sales) and click OK.
  3. Right-click and drag [Order Date] to the Columns shelf.
  4. In the Drop Field menu, select MY(Month).
  5. On the Marks card, select Bar from the dropdown menu.
     

Create the necessary Calculated Fields

  1. Select Analysis > Create Calculated Field
  2. 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 Margin"
    • In the formula field, create the desired calculation for either Standard Error or 95% Confidence Interval
    The formula for standard error may look like:

    STDEV([Sales])/SQRT(COUNT([Sales]))

    The formula for 95% confidence interval may look like:

    1.96 * ( STDEV([Sales]) / SQRT(COUNT( [Sales] ))  )

  3. Create a calculated field with a name like "Sales lower bar" with a calculation similar to the following:  

    AVG([Sales])-([Sales Margin])

  4. Create a calculated field with a name like "Sales upper bar" with a calculation similar to the following:

    AVG([Sales])+([Sales Margin])

  5. Create a calculated field with a name like "Sales bar length" with a calculation similar to the following:

    [Sales upper bar]-[Sales lower bar]

Create the Error Bars

  1. Drag [Sales lower bar] and [Sales upper bar] to Detail on the Marks card
  2. Right-click the axis in the view and select Add Reference Line
  3. In the Add Reference Line, Band, or Box dialog, do the following and click OK:
    • Select Band
    • For Scope, select Per Cell
    • For Band From in the Value dropdown, select AGG(Sales lower bar)
    • For Band From in the Label dropdown, select None
    • For Band To in the Value dropdown, select AGG(Sales upper bar)
    • For Band To in the Label dropdown, select None
    • For Formatting in the Line dropdown, select the desired line color and weight
    • For Formatting in the Fill dropdown, select None
  4. Drag a second copy of [Sales lower bar] to the Rows shelf
  5. Click on the AGG(Sales lower bar) Marks card to open that card
  6. On the Marks card, select Gantt from the dropdown
  7. Drag [Sales bar length] onto Size on the Marks card
  8. Click Size on the Marks card and adjust the slider to the desired thickness
  9. Click on Color on the Marks card and select a color to match the reference lines
  10. Right-click AGG(Sales lower bar) on the Rows shelf and check Dual Axis
  11. Click on the All Marks card to open that card
  12. Remove [Measure Names] from Color
Did this article resolve the issue?