Cre*_*eep 11 excel pivot-table calculated-columns
我有一个简单的表,其中包含一些数量和间隔,以秒为单位和产品名称.
Month | Product | Amount | Interval in sec
------------------------------------------
05-'12| Prod A | 10 | 5
05-'12| Prod A | 3 | 5
05-'12| Prod B | 4 | 5
05-'12| Prod C | 13 | 5
05-'12| Prod C | 5 | 5
Run Code Online (Sandbox Code Playgroud)
从这个表中我得到了一个数据透视表,其中包含SUM(金额),AVERAGE(以秒为单位的间隔)按月和产品.
Month | Product | SUM of Amount | AVG of Interval in sec
--------------------------------------------------------
05-'12| Prod A | 13 | 5
05-'12| Prod B | 4 | 5
05-'12| Prod C | 18 | 5
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.现在我想为我的数据透视表添加额外的列,并以秒为单位给出间隔量的数量/ AVG的结果.
添加计算值=SUM(Amount)/AVERAGE(Interval)并不能给我正确的值.Excel给了我:
Month | Product | SUM of Amount | AVG of Interval in sec | Amount per sec
-------------------------------------------------------------------------
05-'12| Prod A | 13 | 5 | 1.3
05-'12| Prod B | 4 | 5 | 0.8
05-'12| Prod C | 18 | 5 | 1.8
Run Code Online (Sandbox Code Playgroud)
它实际上做的是=每个月的Sum(Amount)/ SUM(以秒为单位)和基于第一个表中的值的Product.但我正在寻找:
Month | Product | SUM of Amount | AVG of Interval in sec | Amount per sec
-------------------------------------------------------------------------
05-'12| Prod A | 13 | 5 | 2.6
05-'12| Prod B | 4 | 5 | 0.8
05-'12| Prod C | 18 | 5 | 3.6
Run Code Online (Sandbox Code Playgroud)
因此,通过枢轴字段"以秒为单位的AVG"来划分枢轴字段"数量之和".
怎么做到这一点?
小智 8
如果其他人遇到此问题,我发现的解决方案是在数据集中添加帮助"计数"列,其中每个记录在"计数"字段下输入1.
然后,为了达到平均值的效果,您可以使用:
SUM(FIELD_TO_AVERAGE)/SUM(COUNT)
我相信这应该适用于需要平均值的所有情况,但我没有对它进行过广泛的测试.
您需要在公式中引用数据透视表数据,如下所示:
=GETPIVOTDATA("Sum of Amount",$A$3,"Product","A")/GETPIVOTDATA("Average of Interval",$A$3,"Product","A")
编辑: 从电子表格中:要将所需的列添加到数据透视表 A:
K5=GETPIVOTDATA("Sum of Amount",$H$2,"Month",DATE(2012,5,1),"Product","Prod A")/GETPIVOTDATA("Average of Interval",$H$2,"Month",DATE(2012,5,1),"Product","Prod A")
K6=GETPIVOTDATA("Sum of Amount",$H$2,"Month",DATE(2012,5,1),"Product","Prod B")/GETPIVOTDATA("Average of Interval",$H$2,"Month",DATE(2012,5,1),"Product","Prod B")
K7=GETPIVOTDATA("Sum of Amount",$H$2,"Month",DATE(2012,5,1),"Product","Prod C")/GETPIVOTDATA("Average of Interval",$H$2,"Month",DATE(2012,5,1),"Product","Prod C")
Run Code Online (Sandbox Code Playgroud)
您还可以通过向原始数据表添加额外的列来生成该列:每个单独条目的金额/秒,然后当您旋转所有数据时,该列的乘积将是您想要的结果。
编辑(2):
上面的公式是单元格公式,而不是数据透视表公式,不能使用引用,抱歉我没有说清楚。我正在研究数据透视表计算公式,但现在上面作为数据透视表旁边的一列应该会产生您需要的内容。
| 归档时间: |
|
| 查看次数: |
59982 次 |
| 最近记录: |