简体   繁体   English

SSAS累积总和计算速度慢

[英]Slow SSAS cumulative sum calculated measure

I have a cumulative sum of a measure structured as: 我有一个度量的累积总和,其结构如下:

Aggregate (
    { NULL : [Date].[Year - Month - Date].CurrentMember } 
    ,[Measures].[Applications] )

From the date of the first application to the current date, the days of the date range must be contiguous. 从首次申请的日期到当前日期,日期范围内的日期必须连续。

The Date dimension however contains dates ranging from 1900-01-01 to well into the future. 但是,“日期”维度包含的日期范围从1900-01-01到将来的日期。

I've attempted to eliminate dates before the first application, and future dates by structuring the calculated measure as follows: 我试图通过按以下方式构造计算得出的度量来消除第一个应用程序之前的日期和将来的日期:

CREATE MEMBER CURRENTCUBE.[Measures].[Applications TD] AS
CASE 
WHEN   
    /* Eliminates dates before first applications, i.e. year 1900-01-01 */
    Aggregate (
        { NULL : [Date].[Year - Month - Date].CurrentMember } 
        ,[Measures].[Applications] ) < 0   
THEN NULL
WHEN
    /* Eliminates dates after today */
    [Date].[Year - Month - Date].CurrentMember.MemberValue >= StrToMember('[Date].[Date].&['+Format(Now(),"yyyy-MM-ddT00:00:00")+']').MemberValue 
THEN NULL
ELSE
    Aggregate (
            { NULL : [Date].[Year - Month - Date].CurrentMember } 
            ,[Measures].[Applications] )           
END

I have been unsuccessful in any attempt to optimizing this by aggregating only where needed using a SCOPE as an alternative to the case statement, utilizing EXISTS and EXCEPT functions and many others. 通过使用SCOPE作为case语句的替代项,利用EXISTS和EXCEPT函数以及许多其他函数仅在需要的地方进行聚合来进行优化,我一直没有成功。

When browsing the cube and dimensioning [Measures].[Applications TD] by [Date].[Year - Month - Date] user-defined hierarchy it is terribly slow. 浏览多维数据集并按[Date].[Year - Month - Date]用户定义的层次结构按[Measures].[Applications TD]维度时,它的运行速度非常慢。

IIF is generally faster than CASE , and SUM is often faster than AGGREGATE . IIF通常比CASE快,而SUM通常比AGGREGATE快。
Although your main problem is the second part of your condition using membervalue - is it required or will the following not do the same thing? 尽管您的主要问题是使用membervalue的情况的第二部分-是必需的,还是以下内容不会做同样的事情? :

CREATE MEMBER CURRENTCUBE.[Measures].[Applications TD] AS
IIF(
     SUM (
        { NULL : [Date].[Year - Month - Date].CurrentMember } 
        ,[Measures].[Applications] 
     ) < 0 
   , NULL
   , 
   SUM (
         { NULL : [Date].[Year - Month - Date].CurrentMember } 
          ,[Measures].[Applications] 
    ) 
)

I'd separate this out as a custom member: 我将其作为定制成员分开:

CREATE MEMBER CURRENTCUBE.[Date].[Date].[All].[Today] AS //<< a  little of syntax for this create 
    StrToMember('[Date].[Date].&['+Format(Now(),"yyyy-MM-ddT00:00:00")+']')

Then try a nested IIF : 然后尝试嵌套的IIF

CREATE MEMBER CURRENTCUBE.[Measures].[Applications TD] AS
IIF(
    [Date].[Year - Month - Date].CurrentMember.MemberValue >= [Date].[Date].[All].[Today].MemberValue
   , NULL
   , IIF(
       SUM (
          { NULL : [Date].[Year - Month - Date].CurrentMember } 
          ,[Measures].[Applications] 
       ) < 0 
     , NULL
     , 
     SUM (
           { NULL : [Date].[Year - Month - Date].CurrentMember } 
            ,[Measures].[Applications] 
      ) 
  )
)

BUT

Rather than bothering with the "Today" member it will be a lot more efficient if you add an isToday column to DimDate - then have an attribute of the cubes date dimension using the column. 如果您在DimDate中添加isToday列,然后使用该列具有“多维数据集”日期维度的属性,则不会比“ Today”成员更麻烦。 That way you should be able to simplify this [Date].[Year - Month - Date].CurrentMember.MemberValue >= [Date].[Date].[All].[Today].MemberValue 这样,您应该能够简化此[Date].[Year - Month - Date].CurrentMember.MemberValue >= [Date].[Date].[All].[Today].MemberValue

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

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