s-s-rS 2012 - 针对 OLAP 评估多个参数

Posted

技术标签:

【中文标题】s-s-rS 2012 - 针对 OLAP 评估多个参数【英文标题】:s-s-rS 2012 - Evaluating multiple parameters against OLAP 【发布时间】:2014-04-02 22:34:53 【问题描述】:

我对 MDX 很陌生。我有一个名为 @MeasureType 的多选参数,它有 3 个可能的标签(我知道这个名字很混乱,但“Measure”在这里是一个行业术语):

内容管理系统 赫迪斯 CMS/HEDIS

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

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

如果@MeasureType = “CMS”,那么 Column2 应该是“CMS” 如果@MeasureType = “HEDIS”,那么 Column2 应该是“HEDIS” 如果 @MeasureType = “CMS/HEDIS”,则 Column2 应为“CMS”或“HEDIS” 如果@MeasureType 为全选,则 Column2 应为“CMS”或“HEDIS”或“其他”

为了让逻辑更清楚,这里是你可以用 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 创建第二个(隐藏)参数,我使用一系列评估Parameters!MeasureType.Label 的IIF 设置它。表达式是这样的:

=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]" )
) )

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

[Measure].[MeasureType].&[CMS] [Measure].[MeasureType].&[HEDIS] [Measure].[MeasureType].&[CMS/HEDIS]"

和参数!ContractType.Value 看起来像这样:

[Measure].[MeasureType].&[CMS] [Measure].[MeasureType].&[HEDIS] [Measure].[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

我现在迷路了。任何帮助都将不胜感激!

【问题讨论】:

【参考方案1】:

隐藏参数方法应该可以工作。创建 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]

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

【讨论】:

只是添加到这个。我们倾向于在 s-s-rS 表达式的代码中构建集合表达式,从而将其完全传递给查询,因此只需要一个简单的 STRTOSET。 这行得通!我需要的是参数集中成员的正确语法。关于您上面所说的,您的意思是您在数据集表达式中构建 MDX 并将参数连接到语句中吗?如果是这样,那么这样做而不是将 MDX 中的参数称为@Parm 是否有好处? 不,保留@Param,这是要走的路。我只是想展示如何以更小的步骤构建这些东西。如果您首先在 SSMS 中使用字符串,那么您可以更轻松地让 MDX 查询按您的意愿工作。然后您可以在第二步中对其进行参数化。 非常感谢你们俩!我会发布我最终的结果,以防有人阅读。【参考方案2】:

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

@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]

【讨论】:

以上是关于s-s-rS 2012 - 针对 OLAP 评估多个参数的主要内容,如果未能解决你的问题,请参考以下文章

针对 OLAP / XMLA / SimbaO2X 服务器的 Crystal Reports

如何评估 MDX 在 OLAP 处理中的性能

.Net OLAP Cube Explorer 控件与 HTML5 移动兼容性 [关闭]

s-s-rS 多关键字搜索

如何在 s-s-rS 中评估过去 12 周的表达式

京东OLAP实践之路