知識庫

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


發佈時間 : 01 Mar 2024
上次修改日期 : 04 Mar 2024

問題

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

環境

  • Tableau Desktop

解決方法

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

 

原因

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)
這篇文章是否解決了問題?