Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Jan 2, 2007

Logical Functions: IsSibling(): Conditional Logic within Filter Expressions

By William Pearson

About the Series ...

This article is a member of the series, MDX Essentials. The series is designed to provide hands-on application of the fundamentals of the Multidimensional Expressions (MDX) language, with each tutorial progressively adding features designed to meet specific real-world needs.

For more information about the series in general, as well as the software and systems requirements for getting the most out of the lessons included, please see my first article, MDX at First Glance: Introduction to MDX Essentials. Current updates are assumed for MSSQL Server, MSSQL Server Analysis Services, and the related Books Online and Samples.

Overview

In IsSibling(): Conditional Logic within Calculations, another article within my MDX Essentials series, we introduced the IsSibling() function, from the perspective of its use within a calculation. We discussed the straightforward purpose of this logical function, to return a value indicating whether or not a member we specify is the sibling of another member we specify. (By “sibling,” of course, we mean that the two members share the same parent.) We discussed the manner in which IsSibling() manages to do this, and ways we can leverage the operator to support effective conditional logic to meet various business needs within our own environments.

In this article, we will examine IsSibling(), once again as a conditional logic modifier, but within the context of a filter. Combining IsSibling() with the MDX Filter() function is another way we commonly see it in action in the business environment, and our exposure to the practical aspects of its employment in this way will serve to round out our overall awareness of the potential of IsSibling(). From the perspective of its use in combination with Filter(), this article will include:

  • A review of the general syntax surrounding the function;
  • Illustrative examples of uses of the function in practice exercises;
  • A brief discussion of the MDX results obtained within each of the practice examples.

The IsSibling() Function

Introduction

As we related in IsSibling(): Conditional Logic within Calculations, the Books Online tell us that the IsSibling() function “returns whether a specified member is a sibling of another specified member.” A Boolean value of “True” is returned if the member expression to which the function is applied is a sibling of the second specified member; otherwise IsSibling() returns “False.” In its capacity, as a logical function, to “test” the nature / status of a member, IsSibling() is often employed in conjunction with the IIF function to conditionally return data, such as a member or members (for example, children of a selected member, if they exist, or the selected member if it has no children), or values based upon the nature / status of members.

We will examine in detail the syntax for the IsSibling() function after our customary overview in the Discussion section that follows. Following that, we will conduct practice examples within a couple of scenarios, constructed to support hypothetical business needs that illustrate uses for the function. This will afford us an opportunity to explore some the basic options that IsSibling() can offer the knowledgeable user. Hands-on practice with IsSibling(), where we will create queries that employ the function, will help us to activate what we have learned in the Discussion and Syntax sections.

NOTE: For more detail surrounding the Filter() function, see Basic Set Functions: The Filter() Function, a member of my Database Journal MDX Essentials series.

Discussion

To restate our initial description of its operation, IsSibling() returns “True” if a specified member expression represents a sibling of (that is, shares a parent with) another member that we specify within a given use of the function; otherwise, the function returns “False.” We can use IsSibling() to apply conditional logic based upon the location or existence of members. As we have noted to be the case with most MDX functions and operators, pairing the IsSibling() function with other MDX functions and operators can help us to leverage its power even further.

Let’s look at syntax specifics to further clarify the operation of IsSibling().

Syntax

To review the syntax involved with employing the IsSibling() function, we specify the primary member expression (the member are testing as to “sibling status”) and the secondary member expression (the member against which we are testing the primary member) within parentheses to the immediate right of the function. The function takes the member expressions, which are thus appended to it as its arguments, and returns True if the member denoted by the primary member expression is a sibling of the secondary member (or, in other words, the primary member shares the same parent as the secondary member).

If the member specified by the primary member expression is not a sibling of the secondary member (that is to say, if the primary member has a different parent than the secondary member) a False is returned, as we might expect.

The general syntax is shown in the following string:

IsSibling(Primary_Member_Expression, Secondary_Member_Expression)

We noted the ease with which we can employ IsSibling() in IsSibling(): Conditional Logic within Calculations. We simply place the primary and secondary member expressions, respectively, under consideration in the parentheses to the right of the function. As an example, within a query executed against the sample Adventure Works cube, for the dimension named Geography (with a hierarchy of the same name), the following expression:

ISSIBLING([Geography].[Geography].CURRENTMEMBER,      [Geography].[Geography].[Country].[United States] ) 

returns True if the current member of the Geography dimension / Geography hierarchy is any of the following:

  • Australia
  • France
  • Germany
  • United Kingdom
  • United States

(We note that the primary member appears, as well, having been treated within MDX as its own sibling.)

Depending upon the structure of the query (and specifically upon whether the syntax eliminates nulls), if members of levels subordinate to the Country level, within the Geography hierarchy, were returned in, say, the row axis of the dataset, their values would be null.

NOTE: For information on several of the “relative” functions, of which .CURRENTMEMBER is an example, see my article MDX Member Functions: "Relative" Member Functions, within the Database Journal MDX Essentials series.

We will practice some uses of the IsSibling() function in the section that follows.



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date