KNOWLEDGE BASE

How To Differentiate Marks With Color On Either Side Of Linear Trend Line


Published: 19 Dec 2019
Last Modified Date: 24 Dec 2019

Question

How to differentiate marks with color on either side of linear trend line.

Environment

  • Tableau Desktop

Answer


1. Drag Sales to Columns and choose the aggregation as Sum.

2. Drag Profit to Rows and choose the aggregation as Sum.

3. Drag Product name to Detail.

4. Select the Analytics Pane >  drag trend line and choose Linear.

5. Select Analysis > Create Calculated Field to create a calculated field.

6. In the Calculated Field dialog box that opens, enter a name for the field. In the example workbook, this field is named slope.

7. In the formula field, create a calculated field similar to the following, and then click OK:
WINDOW_COVAR(SUM([Sales]),SUM([Profit]))/WINDOW_VAR(SUM([Sales]))

8. Create another calculated field intercept with the following formula:
WINDOW_AVG(SUM([Profit]))- [slope]*WINDOW_AVG(SUM([Sales]))

9. Create another calculated field Trend Line Color with the following formula: 
SUM([Profit])- [slope]*SUM([Sales])+ [intercept] < 0

10. Drag Trend Line Color calculation to Color on Marks card.

11. Right-click the Trend Line Color on Marks card, select Compute using and Choose Product Name.

12.  Select Analysis > Trend Lines > Edit Trend Lines.

13.  Under Options Include the following fields as factors: deselect the Trend Line Color check box. Click OK.

2
Did this article resolve the issue?