简体   繁体   中英

Tableau: Plot percentage of binary column

Simplified example: column of 'measure' data is binary 0's and 1's. The sum of the column (all the 1's summed) is 3948. The length of the column is 4567. 3948 is 86% of 4567. How do I create a bar chart showing this percentage. All I can get is a bar adding up to 100%.

I've tried absolutely everything in the percentage of dropdown, calculated fields, online tutorials, etc.

Two approaches:

  1. Right click on your measure field on whichever shelf you placed it. Choose Quick Table Calc -> Percentage of Total. Experiment with different settings for "Compute Using" and read about addressing and partitioning of table calculations to learn how to specify percent of "what".

  2. Or create a calculated field specific to your problem defined as below:

    sum(int([my measure field] = 1)) / count(1)

Be sure to set the default number format for your calculated field to a percentage, by right clicking on it in the data pane (left margin) and revising the default properties

Note, the second calculation works because the INT() function converts True to 1 and False to 0, which is useful in several contexts.

You can go about this using the following method

  1. Add 'measure' to Columns and make it a Discrete Dimension
  2. Add SUM(Number of Records) to Rows. This should give you the bar chart you need.

This would help achieve what you are looking to do. For more customization and a better look for the graph you are looking to build in Tableau.

  • Add 'measure' to the colour legend and make it a Discrete Dimension.
  • Add SUM(Number of Records) as a Label and do a '% of Total' quick table calculation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM