Logical Functions: IsSibling(): Conditional Logic within Calculations - Page 3

December 4, 2006

We have specified that the Calendar Date members are to populate the rows axis to provide, to some extent, a quick means of reasonability testing our the logic within the calculation that we have defined, as we shall see.

2.  Execute the query by clicking the Execute button in the toolbar, as shown in Illustration 2.


Illustration 2: Click Execute to Run the Query...

The Results pane is populated by Analysis Services, and the dataset, partially depicted in Illustration 3, appears.


Illustration 3: Results Dataset (Partial View) – IsSibling() Function within a Calculation

In the partial view of the returned dataset, we see that the calculation accomplishes the intended purpose - generating the Order Count for the individual January 2004 dates, which share the same parent member (the month of January, 2004), obviously, as the secondary member expression of January 1, 2004. Again, the conditional test of “sibling-hood” is applied via a calculated member within which we have leveraged the IsSibling() function.

3.  Select File --> Save MDXQuery1.mdx As ..., name the file MDX050-001, and place it in a meaningful location.

Our client colleagues express satisfaction with the contextual backdrop we have established for introducing the IsSibling() function. We will use a similar query within another such example next, to confirm understanding of the concepts. This query will provide an illustration of the use of the IsSibling() function within the context we have already seen, the definition of a calculated member based upon a comparison. And as before, we will base our example upon a local scenario described by the client representatives.

The developers / authors cite the following example as useful. They would like to create a basic query that returns the Customer Count for the respective month, quarter, half-year and annual levels for Calendar Year 2004. In addition, they are interested in seeing a simple 3-month Rolling Average Customer Count, but they wish for this calculated measure to appear only at the month level, and for a null to appear at the quarter, half-year and annual levels, of the Date hierarchy.

They further specify that they wish to see the calculated measure rounded to two decimal places. Finally, they prefer to present the Date hierarchy levels in the columns, and the measures in the rows, of the returned dataset.

4.  Select File ---> New from the main menu.

5.  Select Query with Current Connection from the cascading menu that appears next, as shown in Illustration 4.


Illustration 4: Create a New Query with the Current Connection ...

A new tab, with a connection to the Adventure Works cube (we can see it listed in the selector of the Metadata pane, once again) appears in the Query pane.


-- MDX050-002 ISSIBLING()Function: Conditional Logic in 
--   the Definition of a Calculation
WITH
MEMBER
   [Measures].[3-Mo Rolling Avg Customer Count]
AS
   'IIF(
   
      ISSIBLING([Date].[Calendar].CURRENTMEMBER, 
         [Date].[Calendar].[Month].[January 2004]),
     
             AVG(LASTPERIODS(3, [Date].[Calendar].CURRENTMEMBER), 
         
         [Measures].[Customer Count]),
    
     NULL
    
  )', FORMAT_STRING = "#,###.00" 

SELECT 
    
   {DESCENDANTS(
      [Date].[Calendar].[Calendar Year].[CY 2003]:[CY 2004],
          [Date].[Calendar].[Month],
      SELF_AND_BEFORE)} ON AXIS(0),
    
    
   CROSSJOIN( 
      {[Product].[Product Categories].[Category].[Bikes].CHILDREN },
    
         {[Measures].[Customer Count],
             [Measures].[3-Mo Rolling Avg Customer Count]}
    
         ) ON AXIS(1)
    
FROM
   [Adventure Works]

The Query pane appears, with our input, as depicted in Illustration 5.


Illustration 5: Our Initial Query in the Query Pane ...

Note that we are adding a wider “presentation” date range (by specifying the range between Calendar Year 2003 and Calendar Year 2004 within the row axis) than required by the specification; this is to allow us to see months preceding 2004, so that we can ascertain that the rolling average is working as planned. (We would remove the “[CY 2003]:” portion of the specification after testing the average, as appropriate.)

7.  Execute the query by clicking the Execute button in the toolbar.

The Results pane is, once again, populated by Analysis Services. This time, the dataset (including the most relevant 2004 data - that containing the 3-month Rolling Average Customer Count - along with a couple of the preceding months of 2003), appears as partially shown in Illustration 6.


Illustration 6: Results Dataset (Partial View) – IsSibling() Functions within a Calculation

In the returned dataset, we see that the query appears to meet the business requirements outlined by the client analysts group. We have delivered a simple rolling average, 3-Mo Rolling Avg Customer Count, based upon the total count of customers recorded for a given month (that is, a month that shares the parent of the secondary member expression of January 1, 2004 within the IsSibling() function), plus the two preceding months (as specified within the expression LASTPERIODS(3, [Date].[Calendar].CURRENTMEMBER - the “True” portion of our IsSibling() function - divided by the number of months specified within the Avg() function (3, as we stipulate within the function).

Our calculation employs the IsSibling() function, much in the same manner as we have employed and explained it in our first example above: it supports conditional logic to determine the specified “focus” members of the Date dimension, and then retrieves the associated values based upon the outcome of this test. We can see each of the Customer Count values involved in the calculation of the 3-Mo Rolling Avg Customer Count within the returned data set, together with the average itself, as a means of presenting data useful in helping us to ascertain that our calculations are performing as expected.

Example:

 1,053    Total Customer Count for Jan 2004, Dec 2003 and Nov 2003 (311 + 442 + 300)
 Divided by 3 Mos.
 = 351.00  (as indicated in the 3-Mo Rolling Avg Customer Count for Jan 2004

The client representatives confirm that the immediate goal of a simple Rolling Avg Customer Count, the presentation of which has been dictated by the IsSibling() function in a manner that lends itself to the parameterization objectives that will arise at the reporting layer, (which we have explained within our discussion surrounding the earlier example) has been met. Moreover, they state that the illustration we have provided will be easily extrapolated to other scenarios where they need to perform an action, or to present a value, based upon the outcome of a test as to whether or not a given dimensional member is the sibling of a specified member.

8.  Select File --> Save MDXQuery2.mdx As ..., name the file MDX050-002, and place it in a meaningful location.

9.  Select File --> Exit to leave the SQL Server Management Studio, when ready.

Summary ...

In this article, we exposed another logical function contained within the MDX toolset, the IsSibling() function, whose general purpose, we learned, is to return a value indicating whether or not a member that we specify is the sibling of another member we specify. We learned that a significant part of the utility of the IsSibling() function lies in the fact that it can be used to test whether the member shares the same parent, and, therefore, the same hierarchical “distance” from the parent, as another dimensional member that we specify.

We noted that, similar to other logical functions, IsSibling() can best be employed to apply conditional logic within a couple of primary ways: as a component within a calculation, and as a component within a filter expression. In this article, we concentrated upon IsSibling() from the perspective of its use within a calculation. We discussed the straightforward purpose of the function, to ascertain whether a member is the sibling of another specified member; the manner in which IsSibling() manages to do this; and ways we can leverage the function to support effective conditional logic to meet various business needs within our own environments.

After introducing IsSibling(), we examined the syntax with which we employ the function. We then undertook illustrative examples whereby we put the IsSibling() function to work, within a couple of simple illustrations, to meet the business needs of a hypothetical client. Throughout our practice session, we briefly discussed the results datasets we obtained from each of the queries we constructed.

» 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








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers