过滤度量(或删除异常值)

发布于 2024-08-11 09:58:00 字数 426 浏览 12 评论 0原文

假设我在多维数据集中有一个度量 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 技术交流群。

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

发布评论

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

评论(3

唱一曲作罢 2024-08-18 09:58:00

诀窍在于您需要在您的设备上应用过滤器,而不是在您的测量上。

例如,使用常用的 Microsoft“仓库和销售”演示多维数据集,以下 MDX 将显示销售额大于 2000 美元的所有商店的销售额。

SELECT Filter([Store].[Stores].[Store].members, [Unit Sales] > 2000) ON COLUMNS,
[Unit Sales] ON ROWS
FROM [Warehouse and Sales]

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.

SELECT Filter([Store].[Stores].[Store].members, [Unit Sales] > 2000) ON COLUMNS,
[Unit Sales] ON ROWS
FROM [Warehouse and Sales]
影子的影子 2024-08-18 09:58:00

我在使用 saiku(Mondrain 后端)时遇到了类似的问题,因为我还没有找到“在测量上添加过滤器”的任何明确解决方案,我在这里添加了它,这可能对其他人有用。

在Saiku3.8中,您可以在UI上添加过滤器:“列”->“过滤器”->“自定义”,然后您可能会看到过滤器MDX表达式。

假设我们希望 Ad 中的点击次数大于 1000,然后在其中添加以下行:

[Measures].[clicks] > 1000

保存并关闭,则该过滤器对于点击次数大于 1000 的查找 elem 有效。MDX

如下所示(假设 dt 作为维度,点击次数作为度量) ,我们想找到点击次数超过1000的dt)

WITH
SET [~ROWS] AS
    Filter({[Dt].[dt].[dt].Members}, ([Measures].[clicks] > 1000))
SELECT
NON EMPTY {[Measures].[clicks]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [OfflineData]

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:

[Measures].[clicks] > 1000

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)

WITH
SET [~ROWS] AS
    Filter({[Dt].[dt].[dt].Members}, ([Measures].[clicks] > 1000))
SELECT
NON EMPTY {[Measures].[clicks]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [OfflineData]
百合的盛世恋 2024-08-18 09:58:00

我认为您有两种选择:

1-向您的事实添加列(或基于事实表的数据源视图上的视图),例如:

case when unit_Price>2000 then 1 
     else 0  
end as Unit_Price_Uper_Or_Under_10 

并根据此列值添加一个虚构的维度。
并为新维度添加命名查询(例如 datasourceview 中的 Range_Dimension :
选择 1 作为范围
联合所有
选择 0 作为范围

,之后您将无法像其他维度和属性一样使用此过滤器。

 SELECT [Store].[Stores].[Store].members ON COLUMNS,
[Unit Sales] ON ROWS
FROM [Warehouse and Sales]
WHERE [Test_Dimension].[Range].&[1]

问题是对于每个范围,您都必须添加 When 条件,并且仅当范围是静态的时,此解决方案才是一个好的解决方案。
对于动态范围,最好制定范围(基于离散化方法)

2-基于事实表添加粒度接近事实表的维度
例如,如果我们有带有主键 Sale_id 的事实表。我们可以添加
基于事实表的维度,只有一列 sale_Id 且位于维度使用选项卡
我们可以将此新维度度量组与关系类型Fact相关联,并且
之后在 mdx 中我们可以使用类似的东西:

filter([dim Sale].[Sale Id].[Sale Id].members,[Measures].[Unit Price]>2000)

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:

case when unit_Price>2000 then 1 
     else 0  
end as Unit_Price_Uper_Or_Under_10 

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.

 SELECT [Store].[Stores].[Store].members ON COLUMNS,
[Unit Sales] ON ROWS
FROM [Warehouse and Sales]
WHERE [Test_Dimension].[Range].&[1]

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 add
dimension based on fact table with only one column sale_Id and in dimension Usage tab
we can relate this new dimension and measure group with relation type Fact and
after that in mdx we can use something like :

filter([dim Sale].[Sale Id].[Sale Id].members,[Measures].[Unit Price]>2000)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文