SSRS 2012 - 针对OLAP评估多个参数

时间:2014-04-02 22:34:54

标签: reporting-services ssrs-2008 ssas mdx olap

我对MDX很新。我有一个名为@MeasureType的多选参数,它有3个可能的标签(我知道这个名字令人困惑但是#34;措施"这里是一个行业术语):

  • CMS
  • HEDIS
  • CMS / HEDIS

@MeasureType需要限制两列的结果:MeasureType和ContractType。

参数值逐字映射到MeasureType。为了将它们映射到ContractType,我们需要应用一些逻辑。这是逻辑:

  • 如果@MeasureType =“CMS”,则Column2应为“CMS”
  • 如果@MeasureType =“HEDIS”,则Column2应为“HEDIS”
  • 如果@MeasureType =“CMS / HEDIS”,则Column2应为“CMS”或“HEDIS”
  • 如果@MeasureType为Select All,则Column2应为“CMS”或“HEDIS”或“Other”

只是为了使逻辑清晰,这里是你如何用SQL编写它(有更好的方法来编写它,但它得到了重点):

-- Mimic multi-value parameter as if the user chose SELECT ALL
DECLARE @MeasureType TABLE (ParmValue varchar(20))

    INSERT @MeasureType VALUES ('CMS')
    INSERT @MeasureType VALUES ('HEDIS')
    INSERT @MeasureType VALUES ('CMS/HEDIS')

-- Mimic the logic to assign value(s) @ContractType based on user's selection of @MeasureType
DECLARE @ContractType TABLE (ParmValue varchar(20))

    IF (SELECT 1 FROM @MeasureType WHERE ParmValue = 'CMS') = 1 
        INSERT @ContractType VALUES ('CMS')

    IF (SELECT 1 FROM @MeasureType WHERE ParmValue = 'HEDIS') = 1
        INSERT @ContractType VALUES ('HEDIS')

    IF (SELECT 1 FROM @MeasureType WHERE ParmValue = 'CMS/HEDIS') = 1
        BEGIN
            INSERT @ContractType VALUES ('CMS')
            INSERT @ContractType VALUES ('HEDIS')
        END

    IF (SELECT 1 FROM @MeasureType WHERE ParmValue = 'CMS') = 1
    AND (SELECT 1 FROM @MeasureType WHERE ParmValue = 'HEDIS') = 1
    AND (SELECT 1 FROM @MeasureType WHERE ParmValue = 'CMS/HEDIS') = 1
        BEGIN
            INSERT @ContractType VALUES ('CMS')
            INSERT @ContractType VALUES ('HEDIS')
            INSERT @ContractType VALUES ('Other')
        END

-- Get the results
SELECT MeasureType,
       Measure1,
       Measure2
FROM   Table1
WHERE  MeasureType IN (SELECT ParmValue from @MeasureType)
AND    ContractType IN (SELECT ParmVaque from @ContractType)

我尝试了几种方法。

第一个是为@ContractType创建第二个(隐藏)参数,我使用一系列评估参数的IIF来设置!MeasureType.Label。表达式如下:

=IIF(
JOIN(Parameters!MeasureType.Label) = "CMS CMS/HEDIS HEDIS", 
"[HealthPlan].[ContractType].&[CMS] [HealthPlan].[ContractType].&[HEDIS] [HealthPlan].[ContractType].&[Other]",
IIF( INSTR( JOIN(Parameters!MeasureType.Label), "CMS/HEDIS" ), 
    "[HealthPlan].[ContractType].&[CMS] [HealthPlan].[ContractType].&[HEDIS]",
     IIF( INSTR( JOIN(Parameters!MeasureType.Label), "CMS" ), 
     "[HealthPlan].[ContractType].&[CMS]",
     "[HealthPlan].[ContractType].&[HEDIS]" )
) )

然后我在数据集的Parameters选项卡中声明了这两个参数。我可以在查询设计器中运行MDX,但是当我尝试预览报表时,我收到此错误......“'[HealthPlan]'的语法不正确。”所以我认为参数构造一定有问题。我创建了几个文本框来查看参数的内容。选择SELECT ALL时,JOIN(参数!MeasureType.Value)如下所示:

  • [Measure]。[MeasureType]。& [CMS] [Measure]。[MeasureType]。& [HEDIS] [Measure]。[MeasureType]。& [CMS / HEDIS]"

和参数!ContractType.Value如下所示:

  • [测量]。[MeasureType]。& [CMS] [测量]。[MeasureType]。& [HEDIS] [测量]。[MeasureType]。& [Other]"

这似乎是正确的。这是我用于此方法的MDX ......

SELECT NON EMPTY { [Measures].[Physician Count], 
                   [Measures].[Population], 
                   [Measures].[Unmet],[Measures].[Met] } ON COLUMNS,
 NON EMPTY { (NONEMPTY([Affiliation].[Affiliation1].[Affiliation1].Members, 
                       [Measures].[Population]) *
              NONEMPTY([Affiliation].[Affiliation2].[Affiliation2].Members, 
                       [Measures].[Population]) *
              NONEMPTY([Affiliation].[Affiliation3].[Affiliation3].Members, 
                       [Measures].[Population]) *
              NONEMPTY([Measure].[Registry].[Registry].Members, 
                       [Measures].[Population]) * 
              NONEMPTY(([Measure].[Measure].[Measure].Members,
                        [Measure].[MeasureKey].[MeasureKey].Members,
                        IIf (
                          StrToSet ( @MeasureType, CONSTRAINED ) .Count = 1,
                          StrToSet ( @MeasureType, CONSTRAINED ),
                          [Measure].[MeasureType].Members
                             )

                        ), [Measures].[Population]) *
              NONEMPTY(([Physician].[PCPNameCode].[PCPNameCode].Members, 
                        [Physician].[PCPID].[PCPID].Members, 
                        [Specialty].[Specialty].[Specialty].Members
                        ), [Measures].[Population]) ) 
            } 
              DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS 
FROM (
  SELECT ( StrToSet ( @MeasureType, CONSTRAINED ) ) ON COLUMNS
  FROM (
        SELECT ( StrToSet ( @ContractType, CONSTRAINED ) ) ON COLUMNS
        FROM [Model]
        )
      )
WHERE ( 
    IIf (
      StrToSet ( @ContractType, CONSTRAINED ) .Count = 1,
      StrToSet ( @ContractType, CONSTRAINED ),
      [HealthPlan].[ContractType].CurrentMember
    ) )
CELL Properties Value,BACK_COLOR,FORE_COLOR,FORMATTED_VALUE,FORMAT_STRING,FONT_NAME,FONT_SIZE,FONT_FLAGS

我尝试的另一种方法是通过创建带有case语句的计算成员来评估MDX中的@MeasureType。 MDX如下。当我运行它时,我根本没有结果。

WITH MEMBER [HealthPlan].[ContractType].[ContractType2] 
AS
                CASE @MeasureType
                        WHEN "CMS" THEN "[HealthPlan].[ContractType].&[CMS]"
                        WHEN "CMS/HEDIS" THEN "[HealthPlan].[ContractType].&[CMS] [HealthPlan].[ContractType].&[HEDIS]"
                        WHEN "HEDIS" THEN "[HealthPlan].[ContractType].&[HEDIS]"
                        WHEN "CMS CMS/HEDIS HEDIS" THEN "[HealthPlan].[ContractType].&[CMS] [HealthPlan].[ContractType].&[HEDIS] [HealthPlan].[ContractType].&[Other]"
                END

SELECT NON EMPTY { [Measures].[Physician Count], [Measures].[Population], [Measures].[Unmet],[Measures].[Met] } ON COLUMNS,
 NON EMPTY { (NONEMPTY([Affiliation].[Affiliation1].[Affiliation1].Members, [Measures].[Population]) *
                          NONEMPTY([Affiliation].[Affiliation2].[Affiliation2].Members, [Measures].[Population]) *
                          NONEMPTY([Affiliation].[Affiliation3].[Affiliation3].Members, [Measures].[Population]) *
                          NONEMPTY([Measure].[Registry].[Registry].Members, [Measures].[Population]) * 
                          NONEMPTY(([Measure].[Measure].[Measure].Members,
                                                [Measure].[MeasureKey].[MeasureKey].Members,
                                                IIf (
                                                  StrToSet ( @MeasureType, CONSTRAINED ) .Count = 1,
                                                  StrToSet ( @MeasureType, CONSTRAINED ),
                                                  [Measure].[MeasureType].Members
                                                         )
                                                ), [Measures].[Population]) *
                          NONEMPTY(([Physician].[PCPNameCode].[PCPNameCode].Members, 
                                                [Physician].[PCPID].[PCPID].Members, 
                                                [Specialty].[Specialty].[Specialty].Members
                                                ), [Measures].[Population]) ) 
                        } 
                          DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS 
FROM [Model]
WHERE [HealthPlan].[ContractType].[ContractType2] 
CELL Properties Value,BACK_COLOR,FORE_COLOR,FORMATTED_VALUE,FORMAT_STRING,FONT_NAME,FONT_SIZE,FONT_FLAGS

我现在迷路了。任何帮助都将非常感谢!

2 个答案:

答案 0 :(得分:3)

隐藏的参数方法应该有效。创建MDX集的正确语法是:

{[HealthPlan].[ContractType].&[CMS], [HealthPlan].[ContractType].&[HEDIS]}

要仅测试参数,请使用尽可能短的查询,可能类似于以下

SELECT  { 
     [Measures].[Population] 
 } ON COLUMNS,
StrToSet ( @MeasureType, CONSTRAINED ) 
  ON ROWS
FROM [Model]

如果您遇到问题,请尝试在SSMS中构建MDX查询。使用SSMS,您可以快速检查上面的集合的语法是否正确(可能不是,因为我没有立方体来测试它!):

  SELECT  { 
    [Measures].[Population] 
   } ON COLUMNS,
   StrToSet ( '{[HealthPlan].[ContractType].&[CMS], [HealthPlan].[ContractType].&[HEDIS]}', 
  CONSTRAINED ) 
  ON ROWS
  FROM [Model]

一旦您知道构建集合所需的文本,就可以设置报告服务表达式来构建文本。

答案 1 :(得分:0)

这是对我有用的解决方案。使用正确的语法设置@ContractType是关键。感谢Fillet!

@ContractType设置为...

=IIF(
JOIN(Parameters!MeasureType.Label) = "CMS CMS/HEDIS HEDIS", 
"{[Member].[ContractType].&[CMS], [Member].[ContractType].&[HEDIS], [Member].[ContractType].&[Other]}",
IIF( INSTR( JOIN(Parameters!MeasureType.Label), "CMS/HEDIS" ), 
    "{[Member].[ContractType].&[CMS], [Member].[ContractType].&[HEDIS]}",
     IIF( INSTR( JOIN(Parameters!MeasureType.Label), "CMS" ), 
     "{[Member].[ContractType].&[CMS]}",
     "{[Member].[ContractType].&[HEDIS]}" )
) )

我正在使用的MDX是......

SELECT NON EMPTY { [Measures].[Physician Count], [Measures].[Population], [Measures].[Unmet],[Measures].[Met] } ON COLUMNS,
 NON EMPTY { (NONEMPTY([Affiliation].[Affiliation1].[Affiliation1].Members, [Measures].[Population]) *
              NONEMPTY([Affiliation].[Affiliation2].[Affiliation2].Members, [Measures].[Population]) *
              NONEMPTY([Affiliation].[Affiliation3].[Affiliation3].Members, [Measures].[Population]) *
              NONEMPTY(
                        (
                            [Measure].[Registry].[Registry].Members, 
                            [Measure].[Measure].[Measure].Members,
                            [Measure].[MeasureKey].[MeasureKey].Members,
                            StrToSet ( @MeasureType )
                          ), [Measures].[Population] 
                       ) *
              NONEMPTY(
                        (
                            StrToSet ( @ContractType )
                          ), [Measures].[Population] 
                       ) *
              NONEMPTY(
                        ([Physician].[PCPNameCode].[PCPNameCode].Members, 
                        [Physician].[PCPID].[PCPID].Members, 
                        [Physician].[Specialty].[Specialty].Members
                         ), [Measures].[Population]
                       ) 
             )
            } 
              DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS 
FROM [Model]