使用 MDX 如何创建带参数的动态报表

Using MDX How to create Dynamic Report with parameters

以下是我的MDX,在SQL服务器环境下完美执行。现在,我想使用 SSRS 创建一个动态报告,它将通过从参数中进行选择来为我提供不同年份的结果。我创建了一个名为 'FY' 的参数,我想通过此参数传递年度值,这就是为什么我将此 MDX 作为表达式传递并得到类似 "Query(1,385) Parser: The Syntax for 'MEMBER' is incorrect" 的错误。我不知道我做错了什么?提前致谢

 "WITH                                                                              "+
 "MEMBER [Total] AS                                                                 "+
 "SUM({[Measures].[July],[Measures].[August],[Measures].[September],                "+
 "[Measures].[October], [Measures].[November],                                      "+
"[Measures].[December],[Measures].[January],[Measures].[February],                  "+
"[Measures].[March],[Measures].[April],                                             "+
"[Measures].[May],[Measures].[June]}, [Dim Account].[Account Type].currentmember),  "+
"MEMBER [Percent] AS                                                                "+
"Total/SUM({[Measures].[July],[Measures].[August],[Measures].[September],           "+
"[Measures].[October], [Measures].[November],                                       "+
"[Measures].[December],[Measures].[January],[Measures].[February],                  "+
"[Measures].[March],[Measures].[April],                                             "+
"[Measures].[May],[Measures].[June]}, [Dim Account].[Account Type].[Income]),       "+
"MEMBER [Dim Account].[Account Type].[Gross Profit] AS                              "+
"  [Dim Account].[Account Type].[Income] -                                          "+
"[Dim Account].[Account Type].[Cost of Sales],                                      "+
"MEMBER [Dim Account].[Account Type].[Operating Profit] AS                          "+
"  [Dim Account].[Account Type].[Gross Profit] -                                    "+
"[Dim Account].[Account Type].[Expenses],                                           "+
"MEMBER [Dim Account].[Account Type].[Net Profit] AS                                "+
"  [Dim Account].[Account Type].[Operating Profit] +                                "+
"[Dim Account].[Account Type].[Other Income] -                                      "+
"[Dim Account].[Account Type].[Other Expense],                                      "+
"MEMBER [Dim Account].[Account Type].[EBITDA] AS                                    "+
"  [Dim Account].[Account Type].[Net Profit] +                                      "+
"[Dim Account].[HierarchyAccount].[Account Activity].                               "+
"&[Profit and Loss]&[Expenses]&[Interest] +                                         "+
"[Dim Account].[HierarchyAccount].[Account Activity].                               "+
"&[Profit and Loss]&[Cost of Sales]&[Depreciation]+                                 "+
"[Dim Account].[HierarchyAccount].[Account Activity].                               "+
"&[Profit and Loss]&[Expenses]&[Depreciation]+                                      "+
"[Dim Account].[HierarchyAccount].[Account Activity].                               "+
"&[Profit and Loss]&[Expenses]&[Amortisation],                                      "+
"SELECT {[Measures].[July],[Measures].[August],[Measures].[September],              "+
"[Measures].[October], [Measures].[November],                                       "+
"[Measures].[December],[Measures].[January],[Measures].[February],                  "+
"[Measures].[March],[Measures].[April],                                             "+
"[Measures].[May],[Measures].[June], Total, [Percent]}  ON COLUMNS,                 "+
" {                                                                                 "+
"   [Dim Account].[Account Type].&[Profit and Loss]&[Income],                       "+
"   [Dim Account].[Account Type].&[Profit and Loss]&[Cost of Sales],                "+
"[Dim Account].[Account Type].[Gross Profit],                                       "+
"   [Dim Account].[Account Type].&[Profit and Loss]&[Expenses],                     "+
"[Dim Account].[Account Type].[Operating Profit],                                   "+
"   [Dim Account].[Account Type].&[Profit and Loss]&[Other Income],                 "+
"   [Dim Account].[Account Type].&[Profit and Loss]&[Other Expense],                "+
"[Dim Account].[Account Type].[Net Profit],                                         "+
"[Dim Account].[Account Type].[EBITDA]} ON ROWS                                     "+
"FROM [DSV_IncomeStmt]                                                              "+
"where [Dim Yearto Date].[Fiscal Year].&["+Parameters!FY.Value+"]   "

使用公式代替查询脚本:

    ="SELECT [Measures].[July]  ON COLUMNS, 
 [Dim Account].[Account Type].&[Profit and Loss]&[Income] ON ROWS
FROM [DSV_IncomeStmt]
where [Dim Yearto Date].[Fiscal Year].&["+param+"]"    

表达式非常完美,除了每个成员末尾的“,”。例如,查看 MEMBER 语句的末尾 a 存在,必须从每个 MEMBER 计算中消除

除此之外一切都很完美。

"WITH                                                                               "+
 "MEMBER [Total] AS                                                                 "+
 "SUM({[Measures].[July],[Measures].[August],[Measures].[September],                "+
 "[Measures].[October], [Measures].[November],                                      "+
"[Measures].[December],[Measures].[January],[Measures].[February],                  "+
"[Measures].[March],[Measures].[April],                                             "+
"[Measures].[May],[Measures].[June]}, [Dim Account].[Account Type].currentmember)   "+

顺便说一句 - 在每行的开头添加你的 space - 目前你正在制作一个非常非常大的字符串,其中有很多白色 space。

在每一行的开头创建一个 space 是更好的方法:

" WITH"+
" MEMBER [Total] AS"+                                                                 
" SUM({[Measures].[July],[Measures].[August],[Measures].[September],"+                 
" [Measures].[October], [Measures].[November],"+                                       
" [Measures].[December],[Measures].[January],[Measures].[February],"+                  
" [Measures].[March],[Measures].[April],"+                                             
" [Measures].[May],[Measures].[June]}, [Dim Account].[Account Type].currentmember)"+ 
" MEMBER [Percent] AS"+ 
...
...