KNOWLEDGE BASE

Display zero in a bar chart when there is no data after filtering


Published: 05 Dec 2022
Last Modified Date: 14 Nov 2023

Question

How to display an axis mark on a bar chart when there is zero (0) or no data, due to filtering.

Current Behavior

Using the example below, If you uncheck "AAA" in the filter, the γ axis mark of "BBB" will disappear.
User-added image
 

Desired Behavior

Even if "AAA" is unchecked in the filter, 0 is displayed and the "γ" is still present on the axis. 
User-added image

Environment

  • Tableau Desktop

Answer

As demonstrated in the attached twbx:

1. Open Tableau Desktop and connect to the attached data source "Sample.csv".
2. Create a new calculated field with the following:
    Name : Sales(Lookup)
    Calculation : ZN(LOOKUP(SUM([Sales]),0))
3. Create a new calculated field with the following:
    Name : Area Filter
    Calculation : IFNULL(
                         IFNULL(LOOKUP(ATTR([Area]),0),LOOKUP(ATTR([Area]),-1))
                         ,LOOKUP(ATTR([Area]),1))
4. Drag Area to Rows and Product to Columns.
5. Drag Sales(Lookup) to Rows then right-click and select Edit Table Calculation.
6. Set the table calculation as follows: 
User-added image
7. Drag Sales(Lookup) to Text on the Marks card.
User-added image
8. Drag Area Filter to Filters then click on All.  
User-added image
9. Right-click on Area Filter on the Filter pane and select Show Filter.


Even if "AAA" is unchecked in the filter, 0 is displayed and the "γ" on the axis.
User-added image
Did this article resolve the issue?