Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

Excel pivot table calculated field not behaving as expected

Here is an example of the sort of data I'm working with:

enter image description here

I would like to create a pivot table where the rows are the dates, the columns are the regions, and the values are the percent of total daily transactions that came from that region. So my desired output looks like:

enter image description here

I created a Calculated Field called "PercentOfDailyTransactions" with the formula COUNT(Amount)/'Total Daily Transactions'. Then I created a pivot table with value equal to Sum of PercentOfDailyTransactions.

enter image description here

However, this appears to be calculating 1/(total daily transactions x number of transactions in that region on that day), rather than (number of transactions in that region on that day)/(total daily transactions). For instance, 1/2/2021 in West region should be 3/6=0.5 but is instead 0.0555=1/(3*6). How is Excel getting this value, and how do I create a calculated field that calculates my desired output?

Note that if I add a column to my source table with the formula COUNT([@Amount])/[@[Total Daily Transactions]], then create a pivot table whose values are the sum of that field, that gives me the correct result. However, I would like to be able to accomplish this without adding such a column.

question from:https://stackoverflow.com/questions/65892603/excel-pivot-table-calculated-field-not-behaving-as-expected

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Optional step: I would format your base data set as a table. It might help you later if you're creating more Pivot charts, reporting connections, adding slicers, etc.

Here's what I got

Steps:

  1. Select your data and create a defualt Pivot table
  2. In the PivotTable Fields, drag region into columns, date into rows, and total daily transactions into values. The default for total daily transactions in the Values field is set to Sum, so left click that -> Value field settings -> Count
  3. Right click on any data point in the Pivot table -> Show value as -> % of row total
  4. Done

You can repeat the same steps for Amount, excpet that in the Value field settigns, you keep that as Sum.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...