简体   繁体   English

根据过滤器更改数据透视表中的平均公式

[英]Changing Average Formula in pivot table depending on filter

I have a group of data with the following fields: Code, Product, Rate, Volume 我有一组包含以下字段的数据:代码,产品,费率,数量

Each code has multiple products. 每个代码都有多个产品。 On each row of the pivot table is a code, and the table has a product filter. 数据透视表的每一行上都有一个代码,并且该表具有产品过滤器。 The Rate is the value in the table. 比率是表中的值。 I want that rate to change depending on a combination of products selected. 我希望该汇率根据所选产品的组合而变化。

EG If Code A has: EG如果代码A具有:

  • Product A, 2% Rate, $1000 Volume 产品A,2%的利率,1000美元的交易量
  • Product B, 3% Rate, $3000 Volume 产品B,利率3%,交易量为$ 3000
  • Product C, 1% Rate, $1000 Volume 产品C,1%利率,1000美元交易量

I want the rate field to display 2.4% when all are selected, 2.75% when A&B are selected, 1.5% when A&C are selected and 2.5% when B&C are selected. 我希望比率字段在全部选中时显示2.4%,在选择A&B时显示2.75%,在选择A&C时显示1.5%,并且在选择B&C时显示2.5%。

How do I do this? 我该怎么做呢? Currently, I am only able to have the rate field display an average or a sum, which is not right. 目前,我只能使“费率”字段显示平均值或总和,这是不正确的。 IE in the above example, average would display 2%, which is not accurate. 在以上示例中,IE的平均值将显示2%,这是不准确的。

Its a little convoluted, but I think this gets at what you want. 它有点令人费解,但是我认为这可以满足您的需求。

  1. In your original table of data, create a helper column that multiplies Rate by Volume. 在原始数据表中,创建一个帮助列,将“比率”乘以“体积”。 I will refer to this column as Helper. 我将本专栏称为“助手”。
  2. Select your pivot table, then go to Analyze>Calculations>Fields Items & Sets> Calculated Field 选择数据透视表,然后转到“ Analyze>Calculations>Fields Items & Sets> Calculated Field 在此处输入图片说明
  3. Name your new field Weighted Average then for your formula enter Helper/Volume , then select Add 将新字段命名为“ Weighted Average然后为您的公式输入Helper/Volume ,然后选择Add
  4. Your calculated field will now show the weighted average for each Code based on the filtered Products. 现在,您的计算字段将显示基于已过滤产品的每个代码的加权平均值。 It worked for your simple example, I would think it would work for your larger table. 它适用于您的简单示例,我认为它将适用于较大的表。

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

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