SSAS / SSRS 2008:MDX在日期范围内显示IF

时间:2012-09-16 10:38:30

标签: sql-server-2008 reporting-services ssas mdx

previous question的基础上构建,我尝试在SSRS 2008报告中使用以下结果集。

       Utilisation  New Measure
Apr-12    70.7%        70.7%
May-12    74.5%        74.5%
Jun-12    74.6%        74.6%
Jul-12    76.7%        76.7%
Aug-12    79.5%        79.5%
Sep-12    78.5%        (null)
Oct-12    79.0%        (null)
Nov-12    79.6%        (null)
Dec-12    78.9%        (null)
Jan-13    79.7%        (null)
Feb-13    79.0%        (null)
Mar-13    79.4%        (null)

到目前为止我的MDX查询如下:

WITH MEMBER [Measures].[New Measure]
    AS IIF(
        ISEMPTY(
            EXISTS(
                    [Date].[Fiscal Year-Month].[Fiscal Month].CurrentMember
                    , {[Date].[Fiscal Year-Month].[Fiscal Month].&[2012/13]&[1]
                      :[Date].[Fiscal Year-Month].[Fiscal Month].&[2012/13]&[5]}
                   )
                )
            , NULL
            , [Measures].[Utilisation]
           )
           , FORMAT_STRING = "0.0%"

SELECT      {
            [Date].[Fiscal Year-Month].[2012/13].children
            } ON ROWS

            , 
            {
            [Measures].[Utilisation]
            , [Measures].[New Measure]
            } ON COLUMNS

FROM        [Elective]

虽然New Measure返回与利用率度量相同的结果,并且在几个月内没有返回Null,但我不想要这些值。

2 个答案:

答案 0 :(得分:2)

你很接近,但没有正确的语法。试试这个:

WITH MEMBER [Measures].[New Measure]
    AS IIF(
             EXISTS(
                    {[Date].[Fiscal Year-Month].[Fiscal Month].&[2012/13]&[1]
                    :[Date].[Fiscal Year-Month].[Fiscal Month].&[2012/13]&[5]},
                     [Date].[Fiscal Year-Month].[Fiscal Month].CurrentMember
                   ).Count = 1
            , [Measures].[Utilisation]
            , NULL
           )
           , FORMAT_STRING = "0.0%"

SELECT      {
            [Date].[Fiscal Year-Month].[2012/13].children
            } ON ROWS

            , 
            {
            [Measures].[Utilisation]
            , [Measures].[New Measure]
            } ON COLUMNS

FROM        [Elective]

使用EXISTS函数,第一个参数是要检查的完整集 - 要显示的值的日期范围 - 第二个参数是行上的当前成员,因此您需要执行与原始相反的操作试过。 EXISTS函数返回一个集合,因此您可以使用COUNT函数来查看集合是否有某些东西(当前成员),当匹配时该集合应该只有1。 ISEMPTY不适合您的原因是MDX在计算中包含当前度量,当当前日期成员和Utilization度量值存在时,表达式解析为false并返回Utilization。

答案 1 :(得分:1)

您可以使用Rank功能:

WITH MEMBER [Measures].[New Measure]
    AS IIf(Rank(([Date].[Fiscal Year-Month].[Fiscal Month].CurrentMember)
                , [Date].[Fiscal Year-Month].[Fiscal Month].&[2012/13]&[1]:[Date].[Fiscal Year-Month].[Fiscal Month].&[2012/13]&[5]
                ) < 1
            , NULL
            , [Measures].[Utilisation]
           )