KNOWLEDGE BASE

How to Color Markers within A Range of Days Specified by A Parameter from A Specific Date on A Line Chart


Published: 26 May 2022
Last Modified Date: 08 Jul 2022

Question

How to color markers within a range of days specified by a parameter from a specific date on a line chart.
For example, how to color markers for N days before and after the breakdown dates (4/6 and 4/20) on a line chart that shows the machine's measurement values for each measurement date.

 

Environment

  • Tableau Desktop
  • Windows 10
  • Excel

Answer

Convert breakdown dates to integer and compares serial numbers in a range of days specified by a parameter.

User-added image

1. Place Measurement Date to columns and select discrete.
2. Place Value to rows.
3. Place one more Value to rows and right click Dual Axis.
4. Right click the right Y axis and click Synchronized Axis.
5. Right click the right Y axis and uncheck Show Header.
6. Open SUM(Value)(2) mark card and change mark type to Circle.
7. Create a parameter with integer type and name it Specify a range of days.
8. Right click the Specify a range of days parameter and click Show Parameter.
9. Create a calculated field and name it INT(Breakdown Date).
INT([Breakdown Date])
10. Create a calculated field and name it N days before breakdown.
WINDOW_SUM(SUM([INT(Breakdown Date)]),0,[Specify a range of days])
11. Create a calculated field and name it N days after breakdown.
WINDOW_SUM(SUM([INT(Breakdown Date)]),-[Specify a range of days],0)
12. Create a calculated field and name it Breakdown flag.
IF [N days after breakdown] > 0 AND [N days before breakdown] > 0 
  THEN "Breakdown date" 
ELSEIF [N days after breakdown] > 0 
  THEN "N days after breakdown"
ELSEIF [N days before breakdown] > 0 
  THEN "N days before breakdown"
ELSE "Normal"
END
13. Open SUM(Value)(2) mark card and place Breakdown flag to color.
14. Change the legend colors and parameters as you like.
Did this article resolve the issue?