在mdx中使用iif命名Set

时间:2015-01-27 14:12:10

标签: ssas mdx

我正在尝试使用命名集创建计算维度属性,但我对mdx不是很熟悉。我希望该属性包含基于4个不同属性的值的描述。我试图使用的是以下代码,但它必须具有无效语法(给出错误)。

create set [pet types]
as

iif([Vw Cube Customer Dim].[Has Pet].&[Yes],
    iif([Vw Cube Customer Dim].[Has Cat].&[Yes],
        iif([Vw Cube Customer Dim].[Has Dog].&[Yes],
            iif([Vw Cube Customer Dim].[Has Other Pet].&[Yes],
                "Multiple Pets","Cat and Dog"),
        "Cat"),
    iif([Vw Cube Customer Dim].[Has Dog].&[Yes] 
        and [Vw Cube Customer Dim].[Has Pet].&[Yes],
        "Dog and other Pet","Dog")),
"No Pet")

2 个答案:

答案 0 :(得分:2)

为了提高可读性(但它降低了可扩展性),我宁愿使用具有每个层次结构成员系数的状态矩阵: Pets Matrix

比添加几个成员的权重:

CREATE MEMBER CURRENTCUBE.[Measures].[Has Pet Value] as
IIF([Vw Cube Customer Dim].[Has Pet].CurrentMember
 IS [Vw Cube Customer Dim].[Has Pet].&[Yes],8,0);

CREATE MEMBER CURRENTCUBE.[Measures].[Has Cat Value] as
IIF([Vw Cube Customer Dim].[Has Cat].CurrentMember
 IS [Vw Cube Customer Dim].[Has Cat].&[Yes],4,0);

CREATE MEMBER CURRENTCUBE.[Measures].[Has Dog Value] as
IIF([Vw Cube Customer Dim].[Has Dog].CurrentMember
 IS [Vw Cube Customer Dim].[Has Dog].&[Yes],2,0);

CREATE MEMBER CURRENTCUBE.[Measures].[Has Other Pet Value] as
IIF([Vw Cube Customer Dim].[Has Other Pet].CurrentMember
 IS [Vw Cube Customer Dim].[Has Other Pet].&[Yes],1,0);

最后两位成员:1)获得支持,2)获得理想的结果。

CREATE MEMBER CURRENTCUBE.[Measures].[Pet Types Value] as
([Measures].[Has Pet Value]
+[Measures].[Has Cat Value]
+[Measures].[Has Dog Value]
+[Measures].[Has Other Pet Value]);

CREATE MEMBER CURRENTCUBE.[Measures].[Pet Types] as
case [Measures].[Pet Types Value]
    when 15 then "Multiple Pets"
    when 14 then "Cat and Dog"
    when 13 then "Cat and other Pet"
    when 12 then "Cat"
    when 11 then "Dog and other Pet"
    when 10 then "Dog"
    else "No Pet" end;

为分析添加其他维度/层次结构(让我们说[Vw Cube Customer Dim].[Has Bird].&[Yes])可能会导致添加具有下一个权重的新成员(在此示例中为16)并重新计算[Pet Types Value][Pet Types]

答案 1 :(得分:0)

不确定多维数据集脚本,因为我没有使用这些,但是做了一些谷歌搜索得到了以下内容。

请在没有AND的情况下进行测试,因为我认为这也会导致错误。

而不是“没有宠物”我建议将其更改为null,因此该度量变得稀疏,因为它是olap的一个点。

CREATE MEMBER CURRENTCUBE.Measures.PetType 
AS 
'
iif([Vw Cube Customer Dim].[Has Pet].CurrentMember IS [Vw Cube Customer Dim].[Has Pet].&[Yes],
    iif([Vw Cube Customer Dim].[Has Cat].CurrentMember IS [Vw Cube Customer Dim].[Has Cat].&[Yes],
        iif([Vw Cube Customer Dim].[Has Dog].CurrentMember IS [Vw Cube Customer Dim].[Has Dog].&[Yes],
            iif([Vw Cube Customer Dim].[Has Other Pet].CurrentMember IS [Vw Cube Customer Dim].[Has Other Pet].&[Yes],
                "Multiple Pets","Cat and Dog"),
        "Cat"),
    iif(([Vw Cube Customer Dim].[Has Dog].CurrentMember IS [Vw Cube Customer Dim].[Has Dog].&[Yes]) 
        AND ([Vw Cube Customer Dim].[Has Pet].CurrentMember IS [Vw Cube Customer Dim].[Has Pet].&[Yes]),
        "Dog and other Pet","Dog")),
"No Pet")
'