KNOWLEDGE BASE

How to show/hide labels based on the number of plots in a line chart


Published: 13 Apr 2023
Last Modified Date: 14 Apr 2023

Question

How to show/hide labels based on the number of plots in a line chart.

<Example>
In this case you set parameter named 'Enter the Number of Plots' to 40. 
If the number of plots is 40 or more, the label will not be displayed. 
User-added image
If use filters to reduce the number of items displayed, the number of plots is less than 40, a label will be displayed.
User-added image

Environment

  • Tableau Desktop

Answer

<STEP 1>

1. Connect to Sample Superstore from Tableau Desktop.
2. Right click and drag [Order Date] to Columns -> Select MONTH(Order Date)
User-added image
3. Drag [Sales] to Rows.
4. Drag [Order Date] to Filter Pane -> Select 'Range of Dates'
User-added image
5. Right click on [Order Date] on Filter Pane -> Show Filter

<STEP 2>
-Show/Hide Labels Based on the Number of Plots-
6. Create a new parameter as following. -> Right click on [Enter the Number of Plots] -> Show parameter
User-added image
7. Create a new calculated field as following.
     Name : The number of plots
     Calculation : WINDOW_MAX(INDEX())
8. Create a new calculated field as following.
     Name : Show/Hide Labels
     Calculation :IF [The number of plots] >= [Enter the Number of Plots] THEN NULL
                          ELSE SUM([Sales])
                          END
9. Drag [Show/Hide Labels] to Labels on Marks.
User-added image

 
Did this article resolve the issue?