excel-2010 - "Relationship may be needed"尽管已设置关系

标签 excel-2010 powerpivot

我在 Excel 2010 中有两个简单的表格 - 产品和销售:
enter image description here

然后我将它们链接到 PowerPivot - 并在这里创建了从 Sales.ProductId 到 Products.Id 的关系 - 像这样:

enter image description here

现在,我正在尝试为 Sales 表中的每个 productId 构建一个 Pivot,它还会向我显示 ProductTable 中的 Category 和 PurchasePrice。然而,在这里我被卡住了 - 因为这种关系在某种程度上是错误的。在配置 Pivot 时,我收到一条消息 Relationship may be needed即使关系已经存在。结果 - 错误 - 数据透视表如下所示:enter image description here

尽管我实际上是在努力实现这一目标:
enter image description here

我知道我可以在 PowerPivot 的 Sales 表中创建计算列并使用 RELATED 提取所有需要的数据。 DAX 函数 - 但由于现实世界的项目需要大量的联接和字段,我希望有比这种解决方法更好的解决方案......

我上传了示例文件 here .

最佳答案

彼得 ,

你的问题比我第一次更棘手,我花了很多时间挖掘,但我想我在阅读这个 article about making distinct count in related tables 后找到了解决方案。 .

我已更新您的源文件(以便 Sales 表包含每个产品 1 个以上的销售额)和 uploaded it to my public Dropbox folder .

您可以看到我创建了 4 个新的计算度量来说明我的解决方案并使其更易于理解(Excel 2010 术语,2013 年为计算字段):

销售总价

=SUM(Sales[SalesPrice])

已售产品
=COUNT(Sales[ProductId])

每件购买价格
=CALCULATE(SUM(Products[PurchasePrice]),Sales)

采购总价
=[Purchase Price per Item] * [Product Sold]

这里的主要区别在于计算的公式。每件采购价格 .在 linked article 中详细解释了为什么要在 CALCULATE 函数中对产品购买价格求和的原因。 (即使在有点不同的上下文中):

In this way, any filter active on Sales (the related table) propagates to the lookup table.



可能还有其他一些我错过的部分,但我已经在其他几个例子中尝试过这个,它可以正常工作:

enter image description here

关于excel-2010 - "Relationship may be needed"尽管已设置关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22276975/

相关文章:

粘贴 A x B 模式的 Excel 公式

sql - 如何将数据直接从 Excel 插入 Oracle 数据库

odbc - 使用 ODBC 连接从 MS Excel 中的 Power Pivot 连接到 Plex ERP 数据库

excel - Dax-计算列中变量的语法错误

excel - 如何使重新打开文档时有效的 Excel VBA 函数?

vba - 将整个列(列中的每个值)放入数组中?

excel - 按等级限制累积总和

excel - 如何计算由另一列分组的同一列的时间差?

excel - 枢轴名称未分配,如何调试?

javascript - 像 PowerPivot 表一样使用 sap.ui.table.Table