MDX:创建一个不包括来自不同层次的条目的集合

时间:2017-07-31 07:50:09

标签: ssas mdx olap

我正在尝试创建一个自定义集,它排除了另一个层次结构中的条目,因此我无法使用except函数。我试过这个,但是我收到一条错误消息,说在查询中多次显示层次结构。有人可以告诉我如何以最好的方式做到这一点吗?

WITH 
SET [Market1] AS {
    [Market].[Market].[Market].&[103],
    -([Agency].[Nationality - Consortium - Agency].[Nationality].&[111], 
    [Agency].[Nationality - Consortium - Agency].[Nationality].&[116], 
    [Agency].[Nationality - Consortium - Agency].[Nationality].&[242], 
    [Agency].[Nationality - Consortium - Agency].[Nationality].&[134])
}

编辑:这是我的查询(大多数是从查询构建器构建的)

WITH 
SET [Market1] AS SUM((
    [Market].[Market].[Market].&[103],
    EXCEPT({[Agency].[Nationality - Consortium - Agency].[Nationality].ALLMEMBERS}, 
        {[Agency].[Nationality - Consortium - Agency].[Nationality].&[111], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[116], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[242], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[134]}
    )), [Measures].[Price])
SELECT NON EMPTY [Market1] ON ROWS
FROM ( SELECT ( { StrToMember("[Report Date].[Report Date].&[" + Str(Int(CDbl(Now()) - 38718)) + "]") } ) ON COLUMNS
FROM ( SELECT ( { [Travel Type].[Travel Type].&[101],
                  [Travel Type].[Travel Type].&[102],
                  [Travel Type].[Travel Type].&[103] } ) ON COLUMNS
FROM ( SELECT ( { [Departure Date].[Year].&[2017] } ) ON COLUMNS
FROM [Booking]))) 
WHERE ( [Departure Date].[Year].&[2017], 
        [Travel Type].[Travel Type].CurrentMember,
        StrToMember("[Report Date].[Report Date].&[" + Str(Int(CDbl(Now()) - 38718)) + "]") )

EDIT2:管理一起破解它

WITH 
SET [Market1] AS (
    [Market].[Market].[Market].&[103],
    EXCEPT({[Agency].[Nationality - Consortium - Agency].[Nationality].ALLMEMBERS}, 
        {[Agency].[Nationality - Consortium - Agency].[Nationality].&[111], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[116], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[242], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[134]}
    ))
MEMBER Agg AS SUM  
   ( [Market1], [Measures].[Price]  
    )  
SELECT NON EMPTY Agg ON COLUMNS
FROM ( SELECT ( { StrToMember("[Report Date].[Report Date].&[" + Str(Int(CDbl(Now()) - 38718)) + "]") } ) ON COLUMNS
FROM ( SELECT ( { [Travel Type].[Travel Type].&[101],
                  [Travel Type].[Travel Type].&[102],
                  [Travel Type].[Travel Type].&[103] } ) ON COLUMNS
FROM ( SELECT ( { [Departure Date].[Year].&[2017] } ) ON COLUMNS
FROM [Booking]))) 
WHERE ( [Departure Date].[Year].&[2017], 
        [Travel Type].[Travel Type].CurrentMember,
        StrToMember("[Report Date].[Report Date].&[" + Str(Int(CDbl(Now()) - 38718)) + "]") )

1 个答案:

答案 0 :(得分:0)

你不能这样做。您希望限制来自不同维度的数据,因此您必须使用元组:

WITH 
SET [Market1] AS (
    [Market].[Market].[Market].&[103],
    EXCEPT([Agency].[Nationality - Consortium - Agency].[Nationality].ALLMEMBERS, 
        {([Agency].[Nationality - Consortium - Agency].[Nationality].&[111], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[116], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[242], 
        [Agency].[Nationality - Consortium - Agency].[Nationality].&[134]}
    )