如何在MDX中过滤度量并仅为度量输出单行?

时间:2017-04-21 15:35:46

标签: filter mdx olap

鉴于MDX:

select {[Measures].[Effort], [Measures].[Count]} on columns from [Tickets]

..如何从[Measures].[Effort]过滤出[Measures].[Count]的零(0)值,以便生成的[Measures].[Count]值减少"门票数量&# 34;零(0)努力?

人们会认为过滤掉价值会很容易,但事实并非如此。以下不会减少当然的计数,因为最终的单值输出自然大于零(0):

select {[Measures].[Effort], FILTER([Measures].[Count], [Measures].[Effort] > 0 )} on 0 
from [Tickets]

..另外,请假设数百万票,因此在1号轴上放置票证ID,然后在返回MDX结果后进行过滤然后求和将不会有效率

2 个答案:

答案 0 :(得分:0)

如果性能问题且以下查询太慢:

With 
Member [Measures].[RealCount] as
SUM(
    IIF(
        [Measures].[Effort] > 0,
        [Measures].[Count],
        Null
    )
)

Select 
{[Measures].[Effort],[Measures].[Count],[Measures].[RealCount]} on 0
From [Tickets]

您必须在DWH上对其进行过滤以预先计算实际计数。

答案 1 :(得分:0)

我不确定您的故障单层次结构,所以会猜到这一点,但我会想到这些内容:

WITH MEMBER [Measures].[RealCount] AS 
 SUM(
   [Ticket].[Ticket].[Ticket Id], 
   Iif(
     [Measures].[Effort] > 0
    ,1
    ,NULL
   )
 )
SELECT
  {
    [Measures].[Effort]
   ,[Measures].[Count]
   ,[Measures].[RealCount]
  } on 0
FROM [Tickets];

如果上面给出了正确的结果,那么可以通过将一些逻辑移到cube script来进一步改进 - 这一点:

CREATE HIDDEN SumTicker;
[Measures].[SumTicker] = Iif([Measures].[Effort]  > 0,1,NULL);
NON_EMPTY_BEHAVIOR([Measures].[SumTicker]) = [Measures].[Effort];

然后脚本变为:

WITH MEMBER [Measures].[RealCount] AS 
 SUM(
   [Ticket].[Ticket].[Ticket Id], 
   [Measures].[SumTicker]
 )
SELECT
  {
    [Measures].[Effort]
   ,[Measures].[Count]
   ,[Measures].[RealCount]
  } on 0
FROM [Tickets];