SSAS MDX计算成员,多个范围

时间:2017-05-17 11:57:45

标签: ssas mdx

想象一下尺寸为DimA,DimB,DimC和DimD的立方体。

我想要一个计算成员,只有在针对DimA或DimB进行切片时才应计算。如果只针对DimC或DimD进行切片,那么它应该返回Null。

目前,我已通过使用以下3个计算成员实现了这一目标:

Create Member CurrentCube.[Measures].[CalMeasure1] As Null, VISIBLE = 0; 

SCOPE([Measures].[CalcMeasure1]); 
       SCOPE ([DimA].[DimA].[DimA]); 
            This = [Measures].[Camp Index]; 
       END SCOPE; 
END SCOPE; 


Create Member CurrentCube.[Measures].[CalcMeasure2] As Null, VISIBLE = 0; 

SCOPE([Measures].[CalcMeasure2]); 
       SCOPE ([DimB].[DimB].[DimB]); 
            This = [Measures].[Camp Index]; 

CREATE MEMBER CURRENTCUBE.[Measures].[CalcMeasure3]
 AS IIF(ISEMPTY([Measures].[CalcMeasure1]),[Measures].[CalcMeasure2],[Measures].[CalcMeasure1]), 
VISIBLE = 1  ; 
       END SCOPE; 
END SCOPE; 

我必须创建相当多的这些,所以理想情况下,我想用一个单一的措施,而不是3个单独的措施。我试过创建一个嵌套的范围。我还尝试将两个维度层次结构放在一个范围内。但是,这些方法都不起作用。两种方法都要求对DimA和DimB进行切片。如果针对DimA或DimB进行切片,我需要它才能工作。

注意我上面的代码可以工作,我只是想把它压缩成一个单独的计算成员

编辑:预期结果,针对不同的数据透视表用法。

DimA Attribute    CalcMeasure3  
1                 1.1  
2                 1.1  
3                 8.6  


DimB Attribute    CalcMeasure3  
4                 2.1  
5                 2.1  
6                 9.6  


DimA Attribute    DimC Attribute    CalcMeasure3  
1                 A                 1.1  
2                 B                 1.1  
3                 C                 8.6  


DimB Attribute    DimD Attribute    CalcMeasure3  
4                 D                 1.1  
5                 E                 1.1  
6                 F                 8.6  

DimC Attribute    CalcMeasure3  
A                 (Null)  
B                 (Null)  
C                 (Null)  


DimD Attribute    CalcMeasure3  
D                 (Null)  
E                 (Null)  
F                 (Null)  

2 个答案:

答案 0 :(得分:1)

这个计算出来的措施怎么样,没有范围:

WITH MEMBER [Camp Index] AS
IIF( 
    not ([DimA].[DimA].CurrentMember is [DimA].[DimA].[All]) or not([DimB].[DimB].CurrentMember is [DimB].[DimB].[All]), 
[You Calcuate],
IIF( 
    not ([DimC].[DimC].CurrentMember is [DimC].[DimC].[All]) or not([DimD].[DimD].CurrentMember is [DimD].[DimD].[All]),
    NULL,
    [You Calcuate]
),
NULL 
)
SELECT
{[Camp Index]} on 0
from [Adventure Works]

答案 1 :(得分:0)

我的第一个猜测:

Scope([Measures].[Camp Index]);
    This = IIF(
                [DimC].[DimC].[DimC].CurrentMember is [DimC].[DimC].[All]
                and
                [DimD].[DimD].[DimD].CurrentMember is [DimD].[DimD].[All]
                [Measures].[Camp Index],
                NULL
    );
End Scope;