【问题标题】:Can't get filter to work with multiple conditions无法让过滤器在多个条件下工作
【发布时间】:2013-08-11 04:03:20
【问题描述】:

我正在尝试创建一个 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

谢谢

【问题讨论】:

    标签: filter ssas ssms mdx


    【解决方案1】:

    修改你的查询我最终得到了这个,让我知道它是怎么回事:

    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]
    

    【讨论】:

    • 嗨梅夫,感谢您的回复。通过您的返工,我得到的记录更少,但仍然有很多空值。仅供参考:三月、四月和可能是空的,但我确实得到了那几个月的记录。
    • @Maestrodude 在我意识到错误时进行了编辑-您是在说“逐月显示,并显示在整个日期范围内具有价值的任何人”,您想说“显示给我逐月显示任何对那个月有价值的人”。
    • 再次感谢 :-) 但我仍然得到很多结果为 null。我认为是因为您必须检查每个月以应用过滤器,否则您将获得所有在总数据中得分的客户。
    • @Maestrodude,您能否尝试我在帖子中编辑的第三个查询,看看是否可以解决问题。如果没有你的立方体,我在使用 MDX 时遇到了一些麻烦:/
    • 就行了。现在我得到了预期的结果。非常感谢!
    猜你喜欢
    • 2017-05-15
    • 1970-01-01
    • 2016-10-22
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 2021-12-02
    • 1970-01-01
    相关资源
    最近更新 更多