一个函数,返回指定成员在指定层级或距离该成员的祖先。
Syntax
Level syntax
Ancestor(Member_Expression, Level_Expression)
Numeric syntax
Ancestor(Member_Expression, Distance)
Arguments
Member_Expression
一个有效的多维表达式(MDX)表达式,返回成员。
Level_Expression
一个有效的多维表达式(MDX)表达式,返回一个层级。
距离
一个有效的数值表达式,用来指定距离指定成员的距离。
Remarks
使用 祖先 函数时,你先给函数一个MDX成员表达式,然后给出一个MDX表达式,表示该成员的祖先级别,或者表示该成员以上层数的数值表达式。 有了这些信息, 祖先 函数返回了该级别的祖先成员。
注释
要返回包含祖先成员的集合,而非仅返回祖先成员,可以使用 祖先(MDX) 函数。
如果指定了级别表达式, 祖先 函数返回指定成员在指定级别的祖先。 如果指定的成员不在指定层级的同一层级内,函数会返回错误。
如果指定了距离, 祖先 函数返回的是指定成员的祖先,即成员表达式中指定的层级中向上的步数。 成员可以被指定为属性层级、用户定义层级,或在某些情况下的父子层级的成员。 数字为1返回成员的父级,数字为2则返回成员的祖父母(如果存在的话)。 数字0返回成员本身。
注释
在父级未知或无法命名的情况下,使用这种形式的 祖先 函数。
示例
以下示例使用水平表达式,返回澳大利亚每个 State-Province 的互联网销售金额及其占总互联网销售额的百分比。
WITH MEMBER Measures.x AS [Measures].[Internet Sales Amount] /
(
[Measures].[Internet Sales Amount],
Ancestor
(
[Customer].[Customer Geography].CurrentMember,
[Customer].[Customer Geography].[Country]
)
), FORMAT_STRING = '0%'
SELECT {[Measures].[Internet Sales Amount], Measures.x} ON 0,
{
Descendants
(
[Customer].[Customer Geography].[Country].&[Australia],
[Customer].[Customer Geography].[State-Province], SELF
)
} ON 1
FROM [Adventure Works]
以下示例使用数值表达式,返回澳大利亚每个 State-Province 的互联网销售额及其占所有国家/地区的互联网销售额百分比。
WITH MEMBER Measures.x AS [Measures].[Internet Sales Amount] /
(
[Measures].[Internet Sales Amount],
Ancestor
([Customer].[Customer Geography].CurrentMember, 2)
), FORMAT_STRING = '0%'
SELECT {[Measures].[Internet Sales Amount], Measures.x} ON 0,
{
Descendants
(
[Customer].[Customer Geography].[Country].&[Australia],
[Customer].[Customer Geography].[State-Province], SELF
)
} ON 1
FROM [Adventure Works]