简体   繁体   English

为什么PowerPivot中的计算字段(或度量)属于哪个表很重要?

[英]Why does it matter which table a calculated field (or measure) belongs to in PowerPivot?

I've been using PowerPivot for some time now, and there's still one thing I just don't understand. 我已经使用PowerPivot已有一段时间了,还有一件事我只是不了解。 When you create a measure (except they're now called calculated fields, not measures, in Excel 2013) you can choose which table it belongs to: 创建度量时(在Excel 2013中将度量值现在称为计算字段,而不是度量),您可以选择它所属的表:

在此处输入图片说明

I understand that this will affect where I see the calculated field appear, both in Excel: 我知道这会影响我在Excel中看到计算字段的位置:

在此处输入图片说明

and also in PowerPivot: 在PowerPivot中:

在此处输入图片说明

However, any reference I can find suggests that otherwise it makes no odds which table I put the measure in. In the example in this question, there is a direct relationship between the product and transaction table: 但是,我可以找到的任何参考资料都表明,否则我将度量放入哪个表就不成问题了。在这个问题的示例中,产品表和交易表之间存在直接关系:

在此处输入图片说明

So why when I put the calculated field in the Product table does Excel come up with this CREATE button: 那么,为什么当我将计算所得的字段放入“产品”表中时,Excel却提出了这个CREATE按钮:

在此处输入图片说明

Does it matter in which table I put calculated fields, and what are the rules? 我将计算后的字段放在哪个表中有什么关系,规则是什么? I've searched the Internet and can't find a good answer! 我已经在互联网上搜索了,找不到很好的答案! Thanks in advance. 提前致谢。

It doesn't matter which table you located your calculations. 您在哪个表中定位了计算都没有关系。 In fact, some people recommend you make a dummy table and store all of your calculations in one table . 实际上,有些人建议您制作一个虚拟表并将所有计算结果存储在一个表中

There are a few of things to be aware of: 有几件事要注意:

  1. Make sure any references to columns in your calculations contain both the table and column name. 确保对计算中列的任何引用均包含表名和列名。 Eg, Sum('Transaction'[Quantity]) rather than Sum([Quantity]) 例如,以Sum('Transaction'[Quantity])而不是Sum([Quantity])
  2. Make sure your relationships are defined in the correct direction. 确保在正确的方向上定义了您的关系。 Power Pivot used to fix this for you, but the December 2014 update caused it to stop doing that . Power Pivot曾为您修复此问题,但2014年12月的更新导致它停止了此操作 The arrow should point to your dimension/lookup table and the dot should be on the fact/transaction table. 箭头应指向您的维度/查询表,点应位于事实/交易表上。 It looks like you have this right, but it's something to keep in mind. 看起来您拥有这项权利,但要记住这一点。
  3. You can test your relationships by using RELATED(). 您可以使用RELATED()测试您的关系。 It looks like you have snowflaked out from the product table to another table, and I can't see how SpeciesName or Year are related to TotalQty. 看来您已经从product表中腾出了另一个表,但我看不到SpeciesName或Year与TotalQty有何关系。 You'll find several references to why snowflakes might be a bad idea , but "If it ain't broke, don't fix it". 您会找到关于雪花为什么不是一个好主意的几个参考资料,但是“如果雪花没有破裂,请不要修复它”。 An easy way to figure out if there is a problem with your relationship is to use the RELATED() function to add a value to the table to which it is linked. 确定关系是否存在问题的一种简单方法是使用RELATED()函数向与其链接的表中添加一个值。 For example, let's say you had included ProductName in your pivot table and you wanted to check to see if it was the culprit. 例如,假设您在数据透视表中包含了ProductName,而您想检查它是否是罪魁祸首。 For testing purposes, you could add a calculated column to the Transaction table that is =RELATED('Product'[ProductName]). 为了进行测试,您可以将一个计算列添加到Transaction表中,该列为= RELATED('Product'[ProductName])。 Then you could try using that field to see if it makes a difference. 然后,您可以尝试使用该字段来查看它是否有所不同。 Snowflakes mean you have more complicated relationships than a star schema, but they are perfectly usable as long as you understand how those relationships work. 雪花意味着您的关系比星型方案更为复杂,但是只要您了解这些关系的工作原理,它们就非常有用。

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

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