对SSAS中计算度量的聚合进行了不同的改进

时间:2012-11-02 05:57:07

标签: ssas mdx aggregation

我必须以一种奇怪的方式计算某些东西,并且它在大多数情况下都有效 - 无论是在叶子还是在多维度上的更高级别的聚合。但它没有为一个特定维度提供正确的聚合值。

我现在所拥有的是......

CREATE MEMBER CURRENTCUBE.[Measures].[Active Commitments]
 AS NULL,
FORMAT_STRING = '#,#', 
VISIBLE = 1;    

SCOPE (DESCENDANTS([Date Dimension].[Fiscal Year Hierarchy],,AFTER));     
[Measures].[Active Commitments] =
iif([Constituent Activity].[Type].currentMember.Properties("Name")="Correspondence",
    sum(([Commitment Dates].[Start Date], NULL: [Date Dimension].[Fiscal Year Hierarchy]), [Measures].[Commitment Count]),
    sum(([Commitment Dates].[First Funded Date], NULL: [Date Dimension].[Fiscal Year Hierarchy]), [Measures].[Commitment Count]))
        - sum(([Commitment Dates].[Stop Date],[Commitment].[Was Commitment Ever Active].[Sometime Active], NULL: [Date Dimension].[Fiscal Year Hierarchy]),  [Measures].[Commitment Count]); 
END SCOPE;

SCOPE (DESCENDANTS([Date Dimension].[Fiscal Year Hierarchy],,AFTER));
<Similar to above> 

正如您所看到的,复杂性是一种“承诺”从[Start Date]开始,其他类型从[First Funded Date]开始。

只要选择[Constituent Activity]的多个成员,就会失败,因为在这种情况下,SCOPE语句中currentMember的使用无效。例如,以下MDX成功执行但输出#Error -

select  
    [Measures].[Active Commitments] on columns
    ,[Date Dimension].[Fiscal Year Hierarchy].[Fiscal Year].&[2011\12] on rows
from Compass3
where
    {[Constituent Activity].[Description].[XYZ]
    ,[Constituent Activity].[Description].[ABC]}

我认为我需要在SCOPE语句中编码的是递归...

if a single member of [Constituent Activity] is current
then use the calc as defined above
else use [Measures].[Active Commitments] = sum(all selected members of [Constituent Activity], [Measures].[Active Commitments])

......但是我怎么写呢?

1 个答案:

答案 0 :(得分:1)

您是否可以一直控制回数据仓库/数据源视图?您可以在事实表中添加计算字段,因此您在单元格级别有[承诺活动日期]吗?然后你可以在立方体中做更简单的计数。

我发现从长远来看,在数据仓库中执行业务规则和进行业务计算更有效,更容易。