简体   繁体   中英

How to treat pivot table column names as integer in pivot chart (Excel)

I am trying to plot data in a bar-chart. On the x-axis I want to display the answer category (1-9) and on the y-axis the amount of times it has been chosen. Not every category has been selected, which results in the following pivot table:

        Column Labels                       
        1   4   5   6   7   8   Grand Total
Count   2   12  90  48  56  8   216

When I plot this data, I get the following figure:

The problem is, the pivot table ignores the distance between two categories. In other words, the graph ignores the fact that there are supposed to be a 2, 3, and 9 (with count = 0) on the X-axis.

How can I get the pivot chart to add the missing categories, without sacrificing the versatility of the Pivot-chart and table?

Raw data

I simply organized the data in a column of a table. In that column (workload), a value can occurs once, multiple times, or not at all. I did find a non-pivot-table solution in which I simply used Countif.

Department   Workload     ...    Col_n
2            5            ...
3            5
2            7
1            1
2            6
1            4
...          ...

This is a good question and to answer it correvtly will need access to your original data (where the pivot takes them). However, I will give you a general case and I think you could change it a little to fit your needs.

The problem with pivot tables is that you can't use them to report on data that is not there. So what you can do to fix that is to add the Missing Data.

So the first step is to add some dummy records to the data. You could add one dummy record for each category that is missing.

Now, when the pivot table is refreshed, the missing categories should appear, but with blank cells in the Count. That's close to what we'd like, but it would be preferable to show a zero there.

We should give the pivot table something to count so you could add "X" or "-".

With that change, a number shows up in the Count of ID column, but we want the number to be 0, not 1.

Now you should change change the Summary Function

The worksheet functions include COUNTA, which counts all non-blank cells in a range, and COUNT, which only counts cells with numbers. There are similar functions in a pivot table, but it's confusing, because the pivot table COUNT is like the worksheet COUNTA, and counts text too.

Instead of using Count, you can change the summary function to one that only counts numbers. Then, those characters in the column you count will not be counted.

在此处输入图片说明

To change the summary function:

  1. Select a cell in the Count column of the pivot table.
  2. On the Ribbon, under PivotTable Tools, click the Options tab
  3. In the Active Field group, click Field Settings

In the Value Field Settings dialog box, in the list of functions, click on Count Numbers, then click OK

在此处输入图片说明

The pivot table now shows a zero for the categories with missing data, instead of a blank cell or an incorrect count.

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