过滤度量(或删除异常值)
假设我在多维数据集中有一个度量 foo
,并且我有一个报告要求,即用户希望在报告中看到以下度量:
total foo
total foo excluding instances where foo > 10
total foo excluding instances where foo > 30
处理此问题的最佳方法是什么? 过去,我添加了命名计算,如果 foo > 则返回 NULL
。 10 或者只是 foo
否则。 我觉得必须有一种方法可以在 MDX 中实现此目的(类似于 Filter([Measures].[foo], [Measures].[foo] > 10))
,但我可以我这辈子都别想明白什么了。
有什么想法吗?
Say I have a measure, foo
, in a cube, and I have a reporting requirement that users want to see the following measures in a report:
total foo
total foo excluding instances where foo > 10
total foo excluding instances where foo > 30
What is the best way to handle this?
In the past, I have added Named Calculations which return NULL
if foo > 10
or just foo
otherwise.
I feel like there has to be a way to accomplish this in MDX (something like Filter([Measures].[foo], [Measures].[foo] > 10))
, but I can't for the life of me figure anything out.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
诀窍在于您需要在您的设备上应用过滤器,而不是在您的测量上。
例如,使用常用的 Microsoft“仓库和销售”演示多维数据集,以下 MDX 将显示销售额大于 2000 美元的所有商店的销售额。
The trick is that you need to apply the filter on your set, not on your measure.
For example, using the usual Microsoft 'warehouse and sales' demo cube, the following MDX will display the sales for all the stores where sales were greater than $2000.
我在使用 saiku(Mondrain 后端)时遇到了类似的问题,因为我还没有找到“在测量上添加过滤器”的任何明确解决方案,我在这里添加了它,这可能对其他人有用。
在Saiku3.8中,您可以在UI上添加过滤器:“列”->“过滤器”->“自定义”,然后您可能会看到过滤器MDX表达式。
假设我们希望 Ad 中的点击次数大于 1000,然后在其中添加以下行:
保存并关闭,则该过滤器对于点击次数大于 1000 的查找 elem 有效。MDX
如下所示(假设 dt 作为维度,点击次数作为度量) ,我们想找到点击次数超过1000的dt)
I met similar problem when use saiku (backend with Mondrain), as I haven't found any clear solution of "add filter on measure", I added it here, and that may be useful for other guy.
In Saiku3.8, you could add filter on UI: "column"->"filter"->"custom", then you may see a Filter MDX Expression.
Let's suppose we want clicks in Ad greater than 1000, then add the following line there:
Save and close, then that filter will be valid for find elem with clicks greater than 1000.
The MDX likes below (suppose dt as dimension and clicks as measure, we want to find dt with clicks more than 1000)
我认为您有两种选择:
1-向您的事实添加列(或基于事实表的数据源视图上的视图),例如:
并根据此列值添加一个虚构的维度。
并为新维度添加命名查询(例如 datasourceview 中的 Range_Dimension :
选择 1 作为范围
联合所有
选择 0 作为范围
,之后您将无法像其他维度和属性一样使用此过滤器。
问题是对于每个范围,您都必须添加
When
条件,并且仅当范围是静态的时,此解决方案才是一个好的解决方案。对于动态范围,最好制定范围(基于离散化方法)
2-基于事实表添加粒度接近事实表的维度
例如,如果我们有带有主键
Sale_id
的事实表。我们可以添加基于事实表的维度,只有一列
sale_Id
且位于维度使用选项卡
我们可以将此
新维度
和度量组
与关系类型Fact
相关联,并且之后在 mdx 中我们可以使用类似的东西:
i think you have two choices:
1- Add column to your fact(or view on data source view that is based on fact table)like:
and add a fictitious Dimension based on this columns value.
and add named query for New Dimension(say Range_Dimension in datasourceview :
select 1 as range
union all
select 0 as range
and after taht you cant used this filter like other dimension and attribute.
the problem is for every range you must add
When
condition and only if the range is static this solution is a good solution.and for dynamic range it's better to formulate the range (based on disceretizing method )
2- add dimension with granularity near fact table based on fact table
for example if we have fact table with primary key
Sale_id
.we can adddimension based on fact table with only one column
sale_Id
and indimension Usage tab
we can relate this
new dimension
andmeasure group
with relation typeFact
andafter that in mdx we can use something like :