SSAS根据另一个计算的度量计算度量

时间:2016-11-11 16:58:46

标签: ssas mdx measure

我在下面有一个MDX查询。这个查询有效,问题是它很慢,需要>即使数据集不是很大,也会返回15秒的结果。我认为查询应该在2秒内执行(它也用在登陆页面上,等待时间很麻烦)。由于所有IF THEN ELSE逻辑,[测量]。[星级]导致速度减慢。所有这一切都基于[平均分数],它根据查找表中的范围从查找表中找到[星级]。 对于例如如果[平均分数]< 86,[星级] = 1         如果[平均分数]> = 86且< = 90,[星级] = 2

[平均分数]是一个简单的和/计算。 它可以根据用作参数的日期范围进行更改。 您能否建议在下面的现有查询中进行优化,或者推荐另一种方法来计算[星级]?

MDX查询如下:

    WITH 
       MEMBER [Measures].[MeanScore] AS ([Measures].[Standard Point Assignment - Sum]/[Measures].[Episode Of Care HCAHPS Count])
       MEMBER [Measures].[StarRating] AS 
       CASE 
       WHEN [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember IS [HCAHPS Star Rating].[HCAHPS Star Rating ID].[All] 
          THEN 
         CASE 
           WHEN [Measures].[HSR-HCHCAHPS Domain ID] = TAIL([HCAHPS Star Rating].[HCAHPS Star Rating ID].[HCAHPS Star Rating ID]).Item(0).Item(0).Properties('HCHCAHPS Domain ID') 
                  THEN 
               (
                [Measures].[Rating], 
                Tail([HCAHPS Star Rating].[HCAHPS Star Rating ID].[HCAHPS Star Rating ID]).Item(0).Item(0)
               )
           ELSE 
               (
                [Measures].[StarRating],
                Tail([HCAHPS Star Rating].[HCAHPS Star Rating ID].[HCAHPS Star Rating ID]).Item(0).Item(0).PrevMember
               )
         END 
       ELSE 
         CASE 
           WHEN [Measures].[MeanScore] > [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember.Properties('Start', typed)
           AND [Measures].[HC-HCAHPS Domain ID] = [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember.Properties('HCHCAHPS Domain ID', typed) 
                  THEN 
               (
               [Measures].[Rating], 
                [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember
                )
           ELSE 
               (
                [Measures].[StarRating],
                [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember.PrevMember
               ) 
         END 
     END 
SELECT 
    {
        [Measures].[Episode Of Care HCAHPS Count]
        ,[Measures].[Is Top Box]
        ,[Measures].[CompositeScore]   
        ,[Measures].[PromoterCount]
        ,[Measures].[PromoterPercent]
        ,[Measures].[PassiveCount]
        ,[Measures].[PassivePercent]
        ,[Measures].[DetractorCount]     
        ,[Measures].[DetractorPercent]
        ,[Measures].[StarRating]
        ,[Measures].[MeanScore]
    } ON COLUMNS, 
    NONEMPTYCROSSJOIN
    (
        {NONEMPTY([HCAHPS Domain].[HCAHPS Survey Methodology ID].[HCAHPS Survey Methodology ID])}
        ,DESCENDANTS(StrToSet('[Org Hierarchy].[Parent Key].&[118418]'))
        ,{[HCHCAHPS Domain].[HC Domain Group].[HC Domain Group]}
        ,{[HCHCAHPS Domain].[HCAHPS Domain Name].[HCAHPS Domain Name]}
        ,{[HCAHPS Question Answer].[Question Number].AllMembers}
     ) ON ROWS 
     FROM [CAHPS] 
     WHERE 
     (
        StrToMember("[Date].[Date].&[" + FORMAT(NOW()-365,"yyyy-MM-ddT00:00:00")  + "]",CONSTRAINED):StrToMember("[Date].[Date].&[" + FORMAT(NOW(),"yyyy-MM-ddT00:00:00")  + "]",CONSTRAINED)
     )

1 个答案:

答案 0 :(得分:0)

通常,Analysis Services MDX中的IIF和CASE语句可能会发现某些性能下降。虽然大多数IIF语句都是相对便宜,复杂的嵌套条件(包含大量IIF语句),但这会导致Analysis Services公式引擎最终逐个运行查询。

对于高性能查询,目标是使查询以子空间模式(或块计算)而不是逐个单元模式运行。要在IIF语句的上下文中执行此操作,请尝试使用SCOPE语句。将IIF语句转换为SCOPE的一个很好的参考是Mosha Pasumansky的博文是Performance of IIF function in MDX

顺便提一下,有关子空间计算的更多信息(与逐个单元格相比),请参阅Analysis Services Performance Guide

的第3.2.1节