filter - 无法让过滤器在多个条件下工作

标签 filter ssas ssms mdx

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

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

谢谢

最佳答案

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

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]

关于filter - 无法让过滤器在多个条件下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18143018/

相关文章:

subquery - 在 MDX 中联合两个子选择

sql-server - 设计维度层次结构: Natural or Unnatural

sql-server - 在同一台计算机上从 SQL Server Express 切换到 SQL Server Developer 版本

c# - 使用 Linq 过滤 ComboBox.DataSource?

php - Yii2 - ListView 搜索表单

ssas - 跨交叉连接维度运行总计的 MDX 查询

sql-server - 失去与 Microsoft Azure SQL 数据库的连接

sql-server-2008 - 在 SSMS 中调试时可以设置条件断点吗?

ios - 如何过滤 JSON 数据然后枚举过滤后的数据?

php - Woocommerce 过滤车和类别具体数量