KNOWLEDGE BASE

Unexpected Values Are Displayed When Setting Color on a Bar Chart Displaying Multiple Measures


Published: 01 Mar 2024
Last modified date: 04 Mar 2024

Issue

Unexpected values are displayed when setting Color on a bar chart displaying multiple measures.

For example, assume that you have the following data.

 User-added image

when each measure is calculated as follows, 0 is displayed on each bar after setting Color.

 Field Name: Male
 Formula: COUNT(IF [Gender] = "Male" THEN [ID] END)

 Field Name: Female
 Formula: COUNT(IF [Gender] = "Female" THEN [ID] END)

 User-added image

Environment

  • Tableau Desktop

Resolution

In this case, use SUM instead of COUNT. When aggregating NULLs with SUM function, Tableau Desktop returns NULLs. 
Follow along in the sample packaged workbook found in the Attachments section to compare the difference.

 Field Name: Male (SUM)
 Formula: SUM(IF [Gender] = "Male" THEN 1 END)

 Field Name: Female (SUM)
 Formula: SUM(IF [Gender] = "Female" THEN 1 END)

 User-added image

 

Cause

In the following formula, data records that do not match the IF condition will be NULLs. When counting NULLs, Tableau Desktop returns 0.

 Formula: COUNT(IF [Gender] = "Male" THEN [ID] END)
Did this article resolve the issue?