简体   繁体   English

Excel数据透视表 - 计算总和的平均值

[英]Excel pivot table - average of calculated sums

I'm sure this is simple, but how do I get a pivot table to display an average for a calculated sum of fields? 我确信这很简单,但是如何获得数据透视表以显示计算的字段总数的平均值? In the simplified example, I've filtered out fund x1, and the pivot table is showing the sums of the remaining funds per person. 在简化示例中,我已过滤掉基金x1,数据透视表显示每人剩余资金的总和。 Now how do I get an average by person (so, manually calculated, 3300/3)? 现在我怎么被人平均(这样,手工计算,三分之三千三百)?

I tried using a calculated field, but cannot figure out how it will work because the denominator will change based on how many people will have the funds I'm filtering on. 我尝试使用计算字段,但无法弄清楚它是如何工作的,因为分母将根据有多少人拥有我正在过滤的资金而改变。 If I use the averaging inside the calculated field it goes back to averaging the funds. 如果我使用计算字段内的平均值,它会回到平均资金。

I tried putting the calculation outside the pivot table, and this works, but of course as I filter, my calculated field is no longer adjacent to the pivot table data, instead just floating off on the worksheet by itself. 我尝试将计算放在数据透视表之外,这是有效的,但当然,当我过滤时,我的计算字段不再与数据透视表数据相邻,而只是在工作表上自行浮动。

TIA. TIA。

例

Per request here is the field list - if I try adding an "average of amount" to the value box it averages the fund amounts, instead of the fund amount per person. 这里的每个请求是字段列表 - 如果我尝试在值框中添加“平均金额”,它会平均基金金额,而不是每人的基金金额。 :

在此输入图像描述

Here is working solution: 这是工作解决方案:

Firstly you should install or enable Power Pivot. 首先,您应该安装或启用Power Pivot。 Quoting Microsoft: 引用微软:

Power Pivot is an Excel add-in you can use to perform powerful data analysis and create sophisticated data models. Power Pivot是一个Excel加载项,可用于执行强大的数据 分析和创建复杂的数据模型。

https://support.office.com/en-us/article/Power-Pivot-Powerful-data-analysis-and-data-modeling-in-Excel-a9c2c6e2-cc49-4976-a7d7-40896795d045?ui=en-US&rs=en-US&ad=US https://support.office.com/en-us/article/Power-Pivot-Powerful-data-analysis-and-data-modeling-in-Excel-a9c2c6e2-cc49-4976-a7d7-40896795d045?ui=en-美国和RS = EN-US&AD = US

In newer Excel versions Power Pivot is already installed and you can enable it by going to: 在较新的Excel版本中,已安装Power Pivot,您可以通过以下方式启用它:

File > Options > Advanced > Data > Enable Data Analysis add-ins: Power Pivot, Power View, and Power Map 文件>选项>高级>数据>启用数据分析加载项:Power Pivot,Power View和Power Map

Alright, so you have Power Pivot now and you can see Power Pivot tab. 好吧,现在你有Power Pivot,你可以看到Power Pivot标签。 Please follow the steps below: 请按照以下步骤操作:

  1. Select your data and click add to “data model” icon on Power Pivot tab. 选择您的数据,然后单击“Power Pivot”选项卡上的“添加到数据模型”图标。
  2. In Power Pivot window add column which will count distinct number of persons in the data. 在Power Pivot窗口中添加列,该列将计算数据中不同数量的人员。 =DISTINCTCOUNT([person]) name it for example “DistPersNo”. = DISTINCTCOUNT([person])将其命名为“DistPersNo”。 This is crucial step – Power Pivot enables you to count unique values in selected column. 这是至关重要的一步 - Power Pivot使您可以计算所选列中的唯一值。
  3. Add another column with formula =[amount]/[DistPersNo] name it “PersonAverages”. 使用公式= [amount] / [DistPersNo]添加另一列,将其命名为“PersonAverages”。
  4. In Power Pivot window click PivotTable and add new pivot table to your worksheet. 在Power Pivot窗口中,单击数据透视表并将新的数据透视表添加到工作表。
  5. In Pivot Table add 'persons' to rows and 'amount' to values. 在数据透视表中,将“人员”添加到行,将“数量”添加到值。 Now, if you add 'PersonAverages' to values (sum of it) and filter out fund 'x1' you will achieve desired result ie value of 1100. 现在,如果您将'PersonAverages'添加到值(它的总和)并过滤掉基金'x1',您将获得所需的结果,即值1100。

Hope that helps. 希望有所帮助。

I would add a helper column in column D to count unique customers. 我会在D列中添加一个辅助列来计算唯一客户。

  1. Sort your data by person 按人排序数据
  2. In column D2 put =IF(A2=A1, 1, 0) and call the column UniqueCust 在列D2中放入= IF(A2 = A1,1,0)并调用UniqueCust列
  3. Copy formula down your dataset for all rows 将公式复制到所有行的数据集中
  4. Add the column to your pivot 将列添加到您的数据透视表
  5. Create a formula in your pivot table called Avg per Cust =Value/UniqueCust 在数据透视表中创建一个名为Avg per Cust = Value / UniqueCust的公式

This will flag each row in your data with a 1 if it is the first time a name appears in the column or zero otherwise. 如果名称第一次出现在列中,则会将数据中的每一行标记为1,否则为零。 The pivot table calculation will sum up the total value and divide by the total unique customers. 数据透视表计算将总计总值并除以总独特客户。

  1. Click the pivot table to bring up the field list. 单击数据透视表以显示字段列表。
  2. In the Values section where it says "Sum of Amount" click the drop down. 在“值”部分中,显示“金额总和”,然后单击下拉列表。
  3. Click "Value Field Settings" and choose average from the list in the pop-up. 单击“值字段设置”,然后从弹出窗口中的列表中选择平均值。

在此输入图像描述

I'm assuming that you want the value to come in any pivot table and not in a cell calculated outside the pivot table as a formula. 我假设您希望值在任何数据透视表中,而不是在数据透视表外部计算的单元格中作为公式。

As a workaround you can use another pivot table, which takes the input as the original pivot table to find the average. 作为一种变通方法,您可以使用另一个数据透视表,它将输入作为原始数据透视表来查找平均值。

pivot tables 数据透视表

The second pivot table has data source as- E3:F5 or till whatever row you require. 第二个数据透视表的数据源为-E3 E3:F5或直到您需要的任何行。

You'll have to refresh all so that the second pivot table reflects any changes in the filter of first pivot table. 您必须刷新所有内容,以便第二个数据透视表反映第一个数据透视表的过滤器中的任何更改。

I've hidden (or you can filter it out) the grand total in the first pivot table so that the average gives the average of the sum of the amounts. 我隐藏了(或者你可以过滤掉)第一个数据透视表中的总计,以便平均值给出金额总和的平均值。

Since you didn't mention how you are using the data, I will give a couple of options that could work. 由于您没有提到如何使用数据,因此我将提供一些可行的选项。

If you are the only user of the data or if someone else using the data is pivot table savvy you can use the following field list setups to switch data usage: 如果您是数据的唯一用户,或者使用数据的其他人是数据透视表,您可以使用以下字段列表设置来切换数据使用情况:

Sort by Fund (Note the Fund and Person in the Row labels section) 按基金排序(请注意基金和行标签部分中的人员)

在此输入图像描述

and Sort by Person (Note the reversed position of Fund and Person in the Row labels section) 按人格排序(请注意行标签部分中基金和人员的反转位置)

在此输入图像描述

To simplify the data, you can always minimize the main fields. 要简化数据,您始终可以最小化主要字段。

If you are distributing the pivot table to other people who aren't able or willing to modify the pivot table data, I would recommend setting up two separate pivot tables (using the same data source) with the same setups that I showed above. 如果您将数据透视表分发给其他无法或不愿意修改数据透视表数据的人,我建议您使用上面显示的相同设置设置两个单独的数据透视表(使用相同的数据源)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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