MDX依赖于过滤的行集

时间:2013-11-26 12:46:34

标签: ssas mdx olap

我需要编写一个MDX查询,该查询通过我的TEST_DW中的一组过滤行,如果MyValue <0,则返回BelowZero = 1,否则返回BelowZero = 0。我设法使用下面的MDX完成了这个:

WITH 
MEMBER [Measures].[BelowZero] AS 
    case when ([Measures].[MyValue]) < 0
    then 1
    else 0
end 
SELECT NON EMPTY 
{ 
    [Measures].[BelowZero]
} ON COLUMNS, 
NON EMPTY 
{ 
    ([Accounts].[Number].ALLMEMBERS ) 
} 
ON ROWS FROM 
( 
    SELECT (STRTOMEMBER('[Date].[20130801]', CONSTRAINED) : STRTOMEMBER('[Date].[20130831]', CONSTRAINED)) ON COLUMNS 
    FROM [TEST_DW]
) 

问题是我现在需要总结一下BelowZero的所有值。换句话说,这个MDX应该只给我一个结果,告诉我有多少账户有Measure.MyValue&lt; 0。我不知道WHICH帐户是&lt; 0,但只是一个计数。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

WITH 
MEMBER [Measures].[BelowZero] AS 
    case when ([Measures].[MyValue]) < 0
        then 1
        else 0
    end
MEMBER [Measures].[BelowZeroCount] AS
    SUM([Accounts].[Number].ALLMEMBERS, [Measures].[BelowZero])
SELECT NON EMPTY 
{ 
    [Measures].[BelowZeroCount]
} ON COLUMNS
 FROM 
( 
    SELECT (STRTOMEMBER('[Date].[20130801]', CONSTRAINED) : STRTOMEMBER('[Date].[20130831]', CONSTRAINED)) ON COLUMNS 
    FROM [TEST_DW]
) 

WITH 
MEMBER [Measures].[BelowZeroCount] AS
    Filter([Accounts].[Number].ALLMEMBERS, [Measures].[MyValue]) < 0).Count
SELECT NON EMPTY 
{ 
    [Measures].[BelowZeroCount]
} ON COLUMNS
 FROM 
( 
    SELECT (STRTOMEMBER('[Date].[20130801]', CONSTRAINED) : STRTOMEMBER('[Date].[20130831]', CONSTRAINED)) ON COLUMNS 
    FROM [TEST_DW]
)