使用成員函數
成員函數是一種會傳回成員的多維度運算式 (MDX) 函數。成員函數跟 tuple 函數和 set 函數一樣,對於交涉 Analysis Services 中找到的多維度結構而言不可或缺。
在 MDX 中的許多成員函數中,最重要的一個是 CurrentMember 函數,此函數是用來判斷目前在階層上的成員。下列查詢會說明如何連同 Parent、Ancestor 和 Prevmember 函數來使用它:
WITH
//Returns the name of the currentmember on the Calendar hierarchy
MEMBER MEASURES.[CurrentMemberDemo] AS [Date].[Calendar].CurrentMember.Name
//Returns the name of the parent of the currentmember on the Calendar hierarchy
MEMBER MEASURES.[ParentDemo] AS [Date].[Calendar].CurrentMember.Parent.Name
//Returns the name of the ancestor of the currentmember on the Calendar hierarchy at the Year level
MEMBER MEASURES.[AncestorDemo] AS ANCESTOR([Date].[Calendar].CurrentMember, [Date].[Calendar].[Calendar Year]).Name
//Returns the name of the member before the currentmember on the Calendar hierarchy
MEMBER MEASURES.[PrevMemberDemo] AS [Date].[Calendar].CurrentMember.Prevmember.Name
SELECT{MEASURES.[CurrentMemberDemo],MEASURES.[ParentDemo],MEASURES.[AncestorDemo],MEASURES.[PrevMemberDemo] } ON 0,
[Date].[Calendar].MEMBERS ON 1
FROM [Adventure Works]