简体   繁体   English

计算的度量仅在某些单元格上聚合

[英]Calculated Measure aggregating on certain cells only

I'm trying to figure out how I can create a calculated measure that produces a count of only unique facts in my fact table. 我试图弄清楚如何创建一个计算出的量度,该量度在我的事实表中仅生成唯一的事实计数。 My fact table basically stores events from a historical perspective. 我的事实表基本上是从历史角度存储事件的。 But I need the measure to filter out redundant events. 但是我需要采取措施来过滤掉多余的事件。
Using sales as an example(Since all material around OLAP always uses sales in examples): 以销售为例(由于OLAP周围的所有材料始终在示例中使用销售):

The fact table stores sales EVENTS. 事实表存储销售活动。 When a sale is first made it has a unique sales reference which is a column in the fact table. 首次进行销售时,它具有唯一的销售参考,该参考是事实表中的一列。 A unique sale however can be amended(Items added or returned) or completely canceled. 但是,可以更改唯一销售(添加或退回项目)或完全取消销售。 The fact table stores these changes to a sale as different rows. 事实表将这些更改存储在不同行中。

If I create a count measure using SSAS I get a count of all sales events which means an unique sale will be counted multiple times for every change made to it (Which in some reports is desirable). 如果我使用SSAS创建计数度量,那么我将获得所有销售事件的计数,这意味着对每次销售所做的每次更改都会对其进行多次计数(在某些报告中是可取的)。 However I also want a measure that produces a count of unique sales rather than events but not just based on counting unique sales references. 但是,我还想要一种能够产生唯一销售计数而不是事件的度量,而不仅仅是基于唯一销售参考计数。 If the user filters by date then they should see unique sales that still exist on that date (If a sale was canceled by that date if should not be represented in the count at all). 如果用户按日期进行过滤,那么他们应该会看到在该日期仍然存在的唯一销售(如果在该日期之前取消了销售,那么根本就不应该代表该销售)。

How would I do this in MDX/SSAS? 我将如何在MDX / SSAS中执行此操作? It seems like I need have a count query work from a subset from a query that finds the latest change to a sale based on the time dimension. 似乎我需要从查询子集中找到一个计数查询工作,该查询根据时间维度找到对销售的最新更改。 In SQL it would be something like: 在SQL中,它将类似于:

SELECT COUNT(*) FROM SalesFacts FACT1 WHERE Event <> 'Cancelled' AND
Timestamp = (SELECT MAX(Timestamp) FROM SalesFact FACT2 WHERE FACT1.SalesRef=FACT2.SalesRef)

Is it possible or event performant to have subqueries in MDX? 在MDX中是否可能或事件执行者具有子查询?

In SSAS, create a measure that is based on the unique transaction ID (The sales number, or order number) then make that measure a 'DistinctCount' aggregate function in the properties window. 在SSAS中,创建基于唯一交易ID(销售编号或订单编号)的度量,然后在属性窗口中将该度量设为“ DistinctCount”聚合函数。

Now it should count distinct order numbers, under whichever dimension slice it finds itself under. 现在,它应该计算不同的订单号,无论它位于哪个尺寸切片下。

The posted query might probably be rewritten like this: 发布的查询可能会被这样重写:

SELECT COUNT(DISTINCT SalesRef)
FROM SalesFacts
WHERE Event <> 'Cancelled'

An simple answer would be just to have a 'sales count' column in your fact view / dsv query that supplies a 1 for an 'initial' event, a zero for all subsiquent revisions to the event and a -1 if the event is cancelled. 一个简单的答案就是在事实视图/ dsv查询中有一个“销售计数”列,为“初始”事件提供1,为该事件的所有后续修订提供0,如果事件被取消则为-1。 。 This 'journalling' approach plays nicely with incremental fact table loads. 这种“新闻发布”方法可以很好地处理事实表的增量负载。

Another approach, probably more useful in the long run, would be to have an Events dimension: you could then expose a calculated measure that was the count of the members in that dimension non-empty over a given measure in your fact table. 从长远来看,另一种可能更有用的方法是使用“事件”维度:您可以暴露一个计算得出的度量,该度量是事实表中给定度量上该维度中成员的数量为非空。 However for sales this is essentially a degenerate dimension (a dimension based on a fact table) and might get very large. 但是,对于销售而言,这实际上是退化的维度(基于事实表的维度),并且可能会变得非常大。 This may be inappropriate. 这可能是不合适的。

Sometimes the requirements may be more complicated. 有时要求可能会更复杂。 If you slice by time, do you need to know all the distinct events that existed then , even if they were later cancelled? 如果时间片,你需要知道的一切存在的 ,即使他们后来被取消了不同的事件? That starts to get tricky: there's a recent post on Chris Webb's blog where he talks about one (slightly hairy) solution: 这开始变得棘手:克里斯·韦伯(Chris Webb)的博客上最近发表了一篇文章,他在其中谈论一种(略带毛)的解决方案:

http://cwebbbi.wordpress.com/2011/01/22/solving-the-events-in-progress-problem-in-mdx-part-2role-playing-measure-groups/ http://cwebbbi.wordpress.com/2011/01/22/solving-the-events-in-progress-problem-in-mdx-part-2role-playing-measure-groups/

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

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