简体   繁体   English

计算的成员维组

[英]Calculated Member Dimension Group

I'm pretty new to MDX, so this may be a simple thing... 我是MDX的新手,所以这可能很简单。

I have a Dimension that has members like 'Type A', 'Type B', 'Type C', 'Type D'. 我有一个具有“类型A”,“类型B”,“类型C”,“类型D”的成员的维度。 I want to create a dimension group for these so that: 我想为此创建一个维度组:

  • 'Type A' and 'Type B' would be in a group of 'Type A/B' “类型A”和“类型B”将在“类型A / B”组中
  • 'Type C' would be in a group of 'Type C' “类型C”将在“类型C”的组中
  • 'Type D' would be in a group of 'Other' “类型D”将在“其他”组中

Here is what I have so far: 这是我到目前为止的内容:

WITH MEMBER [NewHierarchy].[Type Group].[Type Group Name] AS
    CASE
        WHEN 
            [Type Hierarchy].[Types].CurrentMember = [Type Hierarchy].[Types].&[Type A]
        THEN
            'Type A/B'
        WHEN 
            [Type Hierarchy].[Types].CurrentMember = [Type Hierarchy].[Types].&[Type B]
        THEN
            'Type A/B'
        WHEN 
            [Type Hierarchy].[Types].CurrentMember = [Type Hierarchy].[Types].&[Type C]
        THEN
            'Type C'
        ELSE
            'Other'
    END

select
    NON EMPTY {
        [Measures].[Type Count],
    } on COLUMNS,
    NON EMPTY {
        [NewHierarchy].[Type Group].[Type Group Name] *
        [Type Hierarchy].[Types].[Types].AllMembers
    } on ROWS
from
    [MyCube]

I'm getting an error of: 我收到以下错误消息:

Query (8, 6) The dimension '[NewHierarchy]' was not found in the cube when the string, [NewHierarchy].[Type Group].[Type Group Name], was parsed. 查询(8,6)解析字符串[NewHierarchy]。[Type Group]。[Type Group Name]时,在多维数据集中找不到维度'[NewHierarchy]'。

How can this be accomplished in an MDX query? 如何在MDX查询中完成? Thanks in advance! 提前致谢!

You cannot generate new hierarchies via MDX. 您不能通过MDX生成新的层次结构。 But you can define new members on existing hierarchies like this: 但是,您可以像这样在现有层次结构上定义新成员:

WITH Member [Type Hierarchy].[Types].[Type A/B] AS
            Aggregate({
                       [Type Hierarchy].[Types].&[Type A],
                       [Type Hierarchy].[Types].&[Type B]
                     })
     Member [Type Hierarchy].[Types].[Other] AS
            [Type Hierarchy].[Types].&[Type D]
select
    NON EMPTY {
        [Measures].[Type Count],
    } on COLUMNS,
    NON EMPTY {
        [Type Hierarchy].[Types].[Type A/B],
        [Type Hierarchy].[Types].&[Type C],
        [Type Hierarchy].[Types].[Other]
    } on ROWS
from
    [MyCube]  

Please note that you need to apply Aggregate on a set if you want to have a single member. 请注意,如果要有一个成员,则需要在Aggregate上应用Aggregate

And another remark: Never use = to compare for "is the same member as". 另一个要注意的是:永远不要使用=来比较“与”是同一成员。 = tests if the numeric values of the current measure are the same. =测试当前度量的数值是否相同。 You would use IS to compare for member identity. 您将使用IS比较成员身份。

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

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