简体   繁体   English

基于另一个计算量度的SSAS计算量度

[英]SSAS Calculated Measure based on another calculated measure

I have a MDX query below. 我在下面有一个MDX查询。 This query works, the problem is it is slow, takes > 15 secs to return results even though the data set is not huge. 此查询有效,但问题是它很慢,即使数据集不大,返回结果也要花费> 15秒的时间。 I believe the query should execute under 2 secs (its also used on a landing page and the wait time is bothersome). 我相信查询应在2秒内执行(它也用于登录页面,等待时间很麻烦)。 The [Measures].[Star Rating] is causing the slow down because of all the IF THEN ELSE logic. 由于所有“ IF THEN ELSE”逻辑,[Measures]。[Star Rating]导致速度变慢。 All its doing is based on the [Mean Score], it finds the [Star Rating] from a lookup table based on the range in the lookup table. 它的所有操作均基于[均值],它根据查找表中的范围从查找表中查找[星级]。 For eg if [Mean Score] < 86, [Star Rating] = 1 if [Mean Score] >= 86 and <= 90, [Star Rating] = 2 例如,如果[平均得分] <86,则[星级评分] = 1,如果[平均得分]> = 86并且<= 90,则[星级评分] = 2

The [Mean Score] is a simple sum/count calculation. [平均得分]是一个简单的总和/计数计算。 It can change based on the date range being used as parameter. 可以根据用作参数的日期范围进行更改。 Can you recommend either an optimization in the existing query below or recommend an alternate way to calculate [Star Rating] ? 您可以在下面的现有查询中推荐优化方案,还是建议一种替代方法来计算“星级”?

The MDX query is below: 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)
     )

In general, IIF and CASE statements within Analysis Services MDX could potentially see some performance degradations. 通常,Analysis Services MDX中的IIF和CASE语句可能会看到性能下降。 While most IIF statements are relatively inexpensive, complex nested conditions (with lots of IIF statements), this would result in the Analysis Services formula engine will end up running the query cell-by-cell. 尽管大多数IIF语句是相对便宜的,复杂的嵌套条件(具有许多IIF语句),但这将导致Analysis Services公式引擎最终将逐个单元地运行查询。

For performant queries, the goal is to have the query run in subspace mode (or block computation) instead of cell-by-cell mode. 对于高性能查询,目标是使查询以子空间模式(或块计算)而不是逐个单元模式运行。 To do this within the context if IIF statements, please try to utilize SCOPE statements. 为此,如果使用IIF语句,请尝试使用SCOPE语句。 A great reference to convert IIF statements to SCOPE is Mosha Pasumansky's blog post is Performance of IIF function in MDX . Mosha Pasumansky的博客文章MDX中的IIF函数的性能是将IIF语句转换为SCOPE一个很好的参考。

By the way, for more information on subspace computation (vs. cell-by-cell), please refer to Section 3.2.1 of the Analysis Services Performance Guide 顺便说一句,有关子空间计算(逐个单元)的更多信息,请参阅《 Analysis Services性能指南》的 3.2.1节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM