MDX Member Functions: The "Family" Functions - Page 5March 24, 2003 The Ancestor() FunctionThe Ancestor() function retrieves the member, at the specified level, or at the specified distance, that is the ancestor (the parent, parent of parent, or higher) of the source member under consideration. Like the .Parent and .Children functions, it travels within a "vertical" scope, moving up between hierarchical levels from the member to which it is applied. A difference exists between the functions, however, in that the Ancestor() function can contain the aforementioned level, or distance, component, as we will discuss in the Syntax section below. SyntaxThe Ancestor() function is applied differently than the .Parent and .Children functions, in that it is not "appended" to the source member. The source member is placed within the parentheses to the right of the word Ancestor, as shown in the following illustration: Ancestor(member, level) Or Ancestor(member, distance) An illustration of the Ancestor() function (using the level target) follows: SELECT
{(Measures.[Warehouse Sales]), (Measures.[Warehouse Cost])} ON COLUMNS,
{(Ancestor([Time].[Year].[1997].[Q2].[4], [Time].[Quarter]))} ON ROWS
FROM [Warehouse]
The result dataset returned would appear as shown in the illustration below:
In the illustration above, a target level that equaled the level of the member within the function would have returned the member itself. If a distance target is specified, the distance component is represented by a number. The number represents "number of hierarchical steps above the source member." The member itself is returned if the number is zero, reasonably enough. PracticeLet's reinforce our understanding of how the Ancestor() function operates by using it in a couple of queries. We will use the second of the syntax structures (Ancestor(member, distance) in our first example. We will return to the MDX Sample Application, and create a query to return the ancestor member two levels above the source member that we used in the Syntax illustration above. We will be specifying the Units Shipped measure as the slicer dimension in this example. 14. Type the following query into the Query pane: -- MDX05-5: Tutorial Query No. 5
SELECT
{(Measures.[Warehouse Sales]), (Measures.[Warehouse Cost])} ON COLUMNS,
{(Ancestor([Time].[Year].[1997].[Q2].[4], 2))} ON ROWS
FROM [Warehouse]
15. Click the Run button to execute the query. We see the result dataset below, which appears in the Results pane as soon as Analysis Services fills the cells specified by the query.
The query delivers the results that we requested: The target member, specified as "two steps above the source member," is Year (two steps above Month in the Time dimension hierarchy), together with the respective total Units Shipped. Now let's illustrate the operation of the Ancestor() function once again, with another example. 16. Type the following into the Query pane: -- MDX05-6: Tutorial Query No. 6
SELECT
{(Measures.[Units Shipped]), (Measures.[Units Ordered])} ON COLUMNS,
{(Ancestor([Store].[Store Country].[USA].[OR].[Portland], 9
[Store].[Store Country]))} ON ROWS
FROM [Warehouse]
Here, we're specifying two unit measures in our columns, and don't, at least in this case, require the slicer specification (WHERE). We are also using the Ancestor() function, this time with the level target, versus the distance target we used in the first practice exercise. Because we specify the Store Country level, with Portland as the source member, we would expect to see USA in the result dataset. We will not be disappointed in our expectations. 17. Click Query on the top menu, and then select Run. The Results pane appears as shown below.
The result dataset displays the USA member, along with the corresponding Units totals. We see that we can obtain the targeted ancestor member with two different approaches. As will be the case with the .Parent and .Children functions that we have explored earlier, we will find the Ancestor() function to be a powerful tool later when we call upon it for use with relative members. Next in Our Series ...In this lesson, MDX Member Functions: The "Family" Functions, we continued the multiple-article Member Functions segment that focuses upon the member functions (and operators, as appropriate) one at a time, contrasting the uses and effects of each. Specifically, we explored the .Parent, .Children and Ancestor() functions, discussing the information they return, together with syntactical points surrounding their use. We illustrated further how to take advantage of these useful functions by performing practice exercises, and commenting on the result datasets we obtained. As a part of the lesson, we also introduced the WHERE clause, within the context of specifying a slicer dimension for some of our queries. In our next lesson, MDX Member Functions: More "Family" Functions, we will expose the .FirstChild, .LastChild, .FirstSibling and .LastSibling member functions. We will discuss each function, illustrate the appropriate syntax required for its use, and test our understanding of how to take advantage of each of these useful functions by performing practice exercises, and commenting on the result datasets we obtain. » See All Articles by Columnist William E. Pearson, III Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum. MDX Essentials Series
The LEVEL_NUMBER Member Property
The LEVEL_UNIQUE_NAME Intrinsic Member Property Intrinsic Member Properties: The HIERARCHY_UNIQUE_NAME Property Intrinsic Member Properties: The DIMENSION_UNIQUE_NAME Property Further Combination of BottomCount() with Other MDX Functions Combine BottomCount() with Other MDX Functions to Add Sophistication Basic Set Functions: The BottomCount() Function, Part I Intrinsic Member Properties: The MEMBER_VALUE Property Intrinsic Member Properties: The MEMBER_UNIQUE_NAME Property Intrinsic Member Properties: The MEMBER_NAME Property Intrinsic Member Properties: The MEMBER_KEY Property Intrinsic Member Properties: The MEMBER_CAPTION Property Set Functions: The StripCalculatedMembers() Function Set Functions: The AddCalculatedMembers() Function MDX Numeric Functions: The Min() Function MDX Numeric Functions: The Max() Function Set Functions: The .AllMembers Function MDX Essentials: Set Functions: The MeasureGroupMeasures() Function String Functions: The .Properties Function, Part II String Functions: The .Properties Function Logical Functions: IsGeneration(): Conditional Logic within Filter Expressions MDX Scripting Statements: Introducing the Simple CASE Statement Logical Functions: IsGeneration(): Conditional Logic within Calculations Logical Functions: IsAncestor(): Conditional Logic within Filter Expressions MDX Clauses and Keywords: Use HAVING to Filter an Axis Logical Functions: IsAncestor(): Conditional Logic within Calculations Logical Functions: IsSibling(): Conditional Logic within Filter Expressions Logical Functions: IsSibling(): Conditional Logic within Calculations MDX Operators: The IsLeaf() Operator: Conditional Logic within Filter Expressions MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations MDX Numeric Functions: The .Ordinal Function Other MDX Entities: Perspectives MDX Operators: The IS Operator MDX Set Functions: The Distinct() Function MDX Set Functions: The ToggleDrillState() Function Set Functions: The DrillUpLevel() Function Set Functions: The DrillDownLevelTop() and DrillDownLevelBottom() Functions MDX Set Functions: DrillDownLevel() MDX Set Functions: The DRILLUPMEMBER() Function MDX Essentials: Set Functions: The DRILLDOWNMEMBERTOP() and DRILLDOWNMEMBERBOTTOM() Functions MDX Essentials : Set Functions: The DRILLDOWNMEMBER() Function MDX Essentials: Drilling Through with MDX: The DRILLTHROUGH Statement MDX Essentials: String Functions: The .UniqueName Function MDX Essentials: String Functions: The .Name Function MDX Essentials: String / Numeric Functions: The CoalesceEmpty() Function MDX Essentials: Basic Set Functions: The TopCount() Function, Part II MDX Essentials: Basic Set Functions: The TopCount() Function, Part I MDX Essentials: Enhancing CROSSJOIN() with Calculated Members MDX Essentials: Set and String Functions: The GENERATE() Function MDX Essentials: The CROSSJOIN() Function: Breaking Bottlenecks MDX Essentials: String / Numeric Functions: More on the IIF() Function MDX Essentials: String / Numeric Functions: Introducing the IIF() Function MDX Essentials: Logical Functions: The IsEmpty() Function MDX Essentials: Basic Set Functions: The EXTRACT() Function MDX Essentials: Numeric Functions: Introduction to the AVG() Function MDX Essentials: Basic Member Functions: The .Item() Function MDX Essentials: Basic Set Functions: Subset Functions: The Subset() Function MDX Essentials: Basic Set Functions: Subset Functions: The Tail() Function MDX Essentials: Basic Set Functions: Subset Functions: The Head() Function MDX Essentials: Basic Set Functions: The CrossJoin() Function MDX Essentials: Basic Numeric Functions: The Count() Function MDX Essentials: Basic Set Functions: The Filter() Function MDX Essentials: Basic Set Functions: The EXCEPT() Function MDX Essentials: Basic Set Functions: The Intersect() Function MDX Essentials: Basic Set Functions: The Union() Function MDX Essentials: Basic Set Functions: The Order() Function MDX Essentials - MDX Time Series Functions, Part III: The LastPeriods() and ParallelPeriod() Functions MDX Time Series Functions, Part II: The OpeningPeriod () and ClosingPeriod() Functions MDX Essentials - MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions MDX Essentials: MDX Member Functions: "Relative" Member Functions MDX Member Functions: The Cousin () Function MDX Essentials: Member Functions: More "Family" Functions MDX Member Functions: The "Family" Functions MDX Essentials: MDX Members: Introducing Members and Member MDX Essentials : MDX Operators: The Basics MDX Essentials: Structure of the MDX Data Model MDX at First Glance: Introduction to SQL Server MDX Essentials |