使用MDX如何使用参数创建动态报告

时间:2015-07-03 02:25:21

标签: parameters mdx ssrs-2012

以下是我的MDX,它在SQL Server环境中完美执行。现在,我想使用SSRS创建一个动态报告,通过从参数中选择,可以给出不同年份的结果。我创建了一个名为'FY'的参数我希望通过此参数传递年度值,这就是为什么我将此MDX作为表达式传递并得到错误,如“查询(1,385)解析器:'成员'的语法不正确”。我不知道我在做什么错?提前致谢

 "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+"]   "

3 个答案:

答案 0 :(得分:1)

表达式非常完美,除了","在每个成员的最后。例如,查看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)   "+

答案 1 :(得分:0)

使用公式代替查询脚本:

$(".videos").click(function() {
    $.fancybox({
        'padding'       : 0,
        'autoScale'     : false,
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'title'         : this.title,
        'width'         : 640,
        'height'        : 385,
        'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
        'type'          : 'swf',
        'swf'           : {
        'wmode'             : 'transparent',
        'allowfullscreen'   : 'true'
        }
    });

    return false;
});

答案 2 :(得分:0)

就在旁边 - 在每行的开头添加你的空间 - 目前你正在制作一个非常大的字符串,带有很多空白区域。

这是在每行开头创建单个空间的更好方法:

" 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"+ 
...
...