Re-create Tableau's Average line using LOD and Table Calculation

by Mary-Leena Tchenkoue

The analytics pane in Tableau allows to quickly create an average line by simple drag and drop. However, it is not possible to make calculations with this average line because Tableau does not allow it to be saved in the data pane. For example if you had a simple bar chart with a reference line and want to colour the bars above this line, you need to add this average value to your data and then use it to make a conditional statement. This average value can be computed with LOD or Table Calculation

Table Calculation

To reproduce the average line that is in the view above with table calculation, create a calculated field.

Next, add this field to details on the marks card. From the analytics pane, drag and drop a reference line to the view on the Pane Tab. In the pop-up window, click the drop down menu on value and choose the calculated field for the window average. In the marks card, make sure to edit the 'Compute using' of this calculated field to the right one. In this case to 'Pane down'. Now you have reproduced the average line from the first figure.

LOD

Using a nested fixed calculation, you want to return the average line in each pane in the first figure above. So create a calculated field

Next, add this field to details on the marks card. From the analytics pane, drag and drop a reference line to the view on the Pane Tab. In the pop-up window, click the drop down menu on value and choose the calculated field for the window average. Now you have reproduced the average line from the first figure.

Finally, to colour the bars that have sales above the average line, create a calcuated field that compares the SUM([Sales]) to the average line (Table Calculation or LOD)

Put this field on colour in the marks card. If using the LOD average line calculation, you are done. The bars should be colored. If using the Table Calculation average line, make sure the 'Compute using' is the right one. It should match the 'Compute using' of the average line calculated field that is also on the marks card. So you should get something like this

Wed 01 Jun 2022

Mon 30 May 2022

Tue 31 May 2022