4

我正在尝试创建一个 MDX 查询,以便稍后与 SSRS 一起使用。从有效的基本查询开始:

Select NON EMPTY {
[Measures].[Score %]
,[Measures].[Month Key]
} on Columns,
NON EMPTY {
([Date].[YMD].[Month Name].&[201301])
* FILTER([Customer].[Customer Full Name].[Customer Full Name].members,
        ([Measures].[Score %], [Date].[YMD].&[201301]) <> null
    AND ([Measures].[Score %], [Date].[YMD].&[201301]) <> 0 ) 
} on Rows

from [Cube]

但这只是一个月。在 SSRS 中,我希望能够选择多个月份,所以我将查询更改为:

Select NON EMPTY {
 [Measures].[Score %]
,[Measures].[Month Key]
} on Columns,
NON EMPTY {
([Date].[YMD].[Month Name].&[201301] : [Date].[YMD].[Month Name].&[201307])
* FILTER([Customer].[Customer Full Name].[Customer Full Name].members,
        ([Measures].[Score %], ([Date].[YMD].&[201301] : [Date].[YMD].&[201307]))<> null
    AND ([Measures].[Score %], ([Date].[YMD].&[201301] : [Date].[YMD].&[201307])) <> 0 )
} on Rows

from [Cube]

但是在这里我得到一个错误:<> 函数需要一个字符串或数字表达式作为 1 参数。使用了元组集表达式。

据我了解,这是因为我在预期一个月的情况下返回了多个月。所以我写下一个查询:

With
Set [QC relation]
as FILTER([Customer].[Customer Full Name].[Customer Full Name].members,
          ([Measures].[Score %], [Date].[YMD].currentmember) <> null
    AND   ([Measures].[Score %], [Date].[YMD].currentmember) <> 0 ) 

Select NON EMPTY {
 [Measures].[Score %]
,[Measures].[Month Key]
} on Columns,
NON EMPTY {
([Date].[YMD].[Month Name].&[201301] : [Date].[YMD].[Month Name].&[201307]) 
* [QC relation]
} on Rows

from [Cube]

但在这里,我的过滤器似乎无法正常工作。它返回每个月数据中带有分数的所有行,所以我有很多空值。

如何在没有空值的情况下获得每个月的正确结果?我在 SQLServer2008 上使用 SSMS/SSAS

谢谢

4

1 回答 1

6

重新处理您的查询我最终得到了这个,让我知道它是怎么回事:

SELECT NON EMPTY 
{
     [Measures].[Score %]
    ,[Measures].[Month Key]
} ON COLUMNS,
NON EMPTY 
{
    ([Date].[YMD].[Month Name].&[201301] : [Date].[YMD].[Month Name].&[201307])
    * 
    FILTER
    (
        [Customer].[Customer Full Name].[Customer Full Name].members,
        SUM({[Date].[YMD].CURRENTMEMBER}, [Measures].[Score %])<> null
        AND 
        SUM({[Date].[YMD].CURRENTMEMBER}, [Measures].[Score %])<> 0
    )
} ON ROWS
FROM [Cube]

或者更简单的版本可能会起作用:

SELECT NON EMPTY 
{
     [Measures].[Score %]
    ,[Measures].[Month Key]
} ON COLUMNS,
NON EMPTY 
{
    ([Date].[YMD].[Month Name].&[201301] : [Date].[YMD].[Month Name].&[201307])
    * 
    FILTER
    (
        [Customer].[Customer Full Name].[Customer Full Name].members,
        [Measures].[Score %] <> null
        AND 
        [Measures].[Score %] <> 0
    )
} ON ROWS
FROM [Cube]

编辑:第三次尝试,让我们看看这是否有效:

SELECT NON EMPTY 
{
     [Measures].[Score %]
    ,[Measures].[Month Key]
} ON COLUMNS,
NON EMPTY 
{
    ([Date].[YMD].[Month Name].&[201301] : [Date].[YMD].[Month Name].&[201307])
    * 
    [Customer].[Customer Full Name].[Customer Full Name].members
} 
HAVING  [Measures].[Score %] <> null
AND [Measures].[Score %] <> 0
ON ROWS
FROM [Cube]
于 2013-08-09T09:21:29.917 回答