我正在尝试制作一个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]
但是我在这里得到一个错误:&lt;&gt; function期望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
由于
答案 0 :(得分: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]