gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:14:04 27 4
gpt4 key购买 nike

我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com