来自同一累积事实表的单独且独立的计数

发布于 2024-12-04 08:05:45 字数 1266 浏览 2 评论 0原文

因此,我有一个基于交易生命周期模型(或累积事实快照表)的销售事实表,具有许多不同的日期键列(如销售日期、退款日期等)。我对每个日期列做了不同的衡量,即非空销售日期键列的总和是[销售数量],非空退款日期键列的总和是[退款数量]等。日期键列与不同的日期键维度相关。销售日期维度和退款日期维度是角色扮演维度,均基于同一个 DimDate 表。还有其他非基于日期的维度,但为了这个示例,我将保持简单 - storeType 还有另一个附加维度(零售、电子商务等)

当我浏览多维数据集时(因为大多数用户会浏览 )并通过 Excel 探索该多维数据集)我可以将 [销售数量] 和 [退款数量] 拖到列部分,然后我可以将 StoreType 维度拖到行部分中,它会正确显示数据,如下所示


                 Number of Sales   Number of Refunds
----------------------------------------------------
Retail           10                8
eCommerce        5                 2

:很好,因为我还没有申请任何日期过滤器,以便它显示所有内容。我已经确认了事实表中的数据,确实,数字是正确的。

但随后我想对 [销售数量] 和 [退款数量] 应用相同的日期过滤器 - 因此我将这两个维度拖动到过滤器区域,并对两者应用相同的日期过滤器 - 当然,两列的数字都相同:


                 Number of Sales   Number of Refunds
----------------------------------------------------
Retail           5                 4
eCommerce        5                 4

..因为我认为通过有效地将一个日期应用于两个日期维度,我将过滤到同一组行(因为它们来自同一个表)。我知道这是不正确的,因为我可以查询事实表中的各个行并看到它们具有不同的值。

基本上,我想要的是将两列一起显示,但实际上它们没有任何共同点。我什至可以在每列上有两个不同的日期过滤器,即显示 2010 财年的所有销售额并显示 2011 财年的所有退款。这又是用户完全可以浏览的,因此必须提供这些措施,而无需执行复杂的 MDX 查询。

我想我可以创建另一个事实表来将相同的数据存储在事务事实表中,然后我可以单独对其进行计数 - 但是使用两个单独的事实表或多或少地对相同的数据进行计数是没有意义的。

知道如何做到这一点吗?帮助!!

So, I have a Sales Fact table, that is based on the transaction lifecycle model (or accumulating fact snapshot table), with very many different date key columns, (like sales date, refunded date, etc). I made different measures for each of the date columns, i.e. Sum of Non-Empty sales date key column is the [Number of Sales], and Sum of Non-Empty refunded date key column is the [Number of Refunds], etc. Each of the date key columns are related to different date key dimensions. The sales date dimension and the refunded date dimension are role playing dimensions, all based on the same DimDate table. There are other non-date based dimensions as well, but for the sake of this example, I will keep it simple - there is another additional dimension for storeType (retail, ecommerce, etc)

When I browse the cube (as most users will browse and explore the cube via excel) I can drag the [Number of Sales] and [Number of Refunds] to the columns section, and then I can drag the StoreType dimension in the rows section, and it displays the data properly as such:


                 Number of Sales   Number of Refunds
----------------------------------------------------
Retail           10                8
eCommerce        5                 2

This is fine, because I haven't applied any date filters so it displays everything. I've confirned the data in the Fact table, and indeed, the numbers are right.

But then I want to apply the same date filter to both the [Number of Sales] and [Number of Refunds] - so I drag both those dimensions to the filter area, and apply the same date filter to both - and of course, the numbers are all the same for both the columns:


                 Number of Sales   Number of Refunds
----------------------------------------------------
Retail           5                 4
eCommerce        5                 4

.. because I think by effectively applying one date towards both the date dimensions, I am filtering down to the same set of rows (being that they are from the same table). I know this is incorrect, because I can query the individual rows from the Fact table and see that they have different values.

Basically, what I want is to show the two columns together, but really they don't have anything in common. I could possibly even have two different date filters on each column, i.e. show all sales for fiscal year 2010 and show all refunds for fiscal year 2011. This is again, completely browsable by the user, so the measures must be made available without having to do complicated MDX queries.

I guess I can create another fact table to house the same data in a transactional fact table, and I can then count it individually - but that makes no sense to have two separate fact tables to more or less count the same thing.

Any idea how to do this? help!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2024-12-11 08:05:45

听起来您可能需要将 case 语句应用于聚合列。类似这样的事情:

SELECT StoreType
     , SUM(CASE WHEN SalesCol IS NOT NULL THEN 1 ELSE NULL END) AS NumSales
     , SUM(CASE WHEN RefundCol IS NOT NULL THEN 1 ELSE NULL END) AS NumRefunds
FROM FactTable
WHERE SaleDate BETWEEN Date1 AND Date2
GROUP BY 1

It sounds like you may need to apply a case statement to your aggregate columns. Something along the lines of this:

SELECT StoreType
     , SUM(CASE WHEN SalesCol IS NOT NULL THEN 1 ELSE NULL END) AS NumSales
     , SUM(CASE WHEN RefundCol IS NOT NULL THEN 1 ELSE NULL END) AS NumRefunds
FROM FactTable
WHERE SaleDate BETWEEN Date1 AND Date2
GROUP BY 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文