如何计算 PowerPivot 中一对多关系中的行数
我正在尝试在 Excel 2010 的新 PowerPivot 附加组件中的 2 个表之间进行我认为相对简单的计算。
我在设置时加载的 2 个表如下:
表 1: FooID、BarID、名称
表 2: BarID、日期
表 1 和表 2 之间存在一对多关系。
我想向表 1 添加一个计算列,该列仅对表 2 中的所有行进行求和。
我尝试过此操作,但没有成功。计算结果每列都为空。 Excel没有报告错误,所以并不是计算无效,它只是做了一些我不理解的事情。
=CALCULATE(COUNTROWS(Table2), Filter(Table2, Table2[BARID] = Table1[BARID]))
我还尝试了一些我认为也可以工作的更简单的方法:
=COUNTROWS(RELATEDTABLE(Table2))
但是这也会导致空值。
我已经确定表 1 和表 2 在 BARID 上有关系。
I'm trying to do what I thought was a relatively simple calculation between 2 tables I have in the new PowerPivot add-on for Excel 2010.
My 2 tables loaded at setup as follows:
Table 1:
FooID, BarID, Name
Table 2:
BarID, Date
There is a 1 to many relationship between Table 1 and 2.
I want to add a calculated column to Table 1 that just does a sum of all the rows in Table 2.
I've tried this with no luck. The calculation results in null in every column. Excel isn't reporting an error, so it's not that the calculation is invalid, it's just doing somethign I"m not understanding.
=CALCULATE(COUNTROWS(Table2), Filter(Table2, Table2[BARID] = Table1[BARID]))
I also tried something simpler that I thought would also work:
=COUNTROWS(RELATEDTABLE(Table2))
However that also results in null.
I have made sure that table 1 and table 2 have a relationship on BARID.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果存在现有关系,=COUNTROWS(RELATEDTABLE(Table2)) 是正确的公式。
可能只是没有匹配的键吗?
您可以尝试使用第一个公式并匹配显式值,例如:
=CALCULATE(COUNTROWS(Table2), Filter(Table2, Table2[BARID] = "SomeBARIDFromTable2"))
无论是否有关系,上述公式都适用于表被定义。
哈特哈,
赫尔沃耶
=COUNTROWS(RELATEDTABLE(Table2)) is the correct formula if there is an existing relationship.
Might it be that there simply are no matching keys?
You can try that by using your first formula and matching an explicit value eg.:
=CALCULATE(COUNTROWS(Table2), Filter(Table2, Table2[BARID] = "SomeBARIDFromTable2"))
The above formula works on tables regardless of wheter a relationship is defined.
HTH,
Hrvoje