| Home | Technical Info | MDX | Software Products | Yukon | Security | Consulting Training | Business |
By Mosha Pasumansky, November 2004
Often I run across MDX expressions which require to apply different formulas based on whether or not current member is some hierarchy is equal to some particular member. For example, we may need to check whether current time member is the very first month, or whether current account is Flow. While the best way to approach those problems is try to split calculation into several calculations, each one with its own scope, it is not always possible, and the checks for member equivalence are done as part of the MDX expression itself, usually inside condition of IIF function. So let's see what is the best way to perform such comparisons both from correctness and performance point of view. I will use the example of check for current account being Flow. So we need to compare two members: On one hand we have MDX expression for the current account - [Account].CurrentMember, and on another hand we have unique name of the Flow account - [Account].&[Flow]. It is not uncommon to see people trying to write something like following:
|
[Account].CurrentMember = [Account].&[Flow] |
While the above expression looks very natural, it is completely wrong ! The reason is that AS2000 implementation of operator "=" can only compare numbers or strings. Therefore the implicit data type conversion from member object to scalar is applied (I hope to write an article about MDX data types and type conversions soon) by converting [Account].CurrentMember to [Account].CurrentMember.Value and converting [Account].&[Flow] to [Account].&[Flow].Value . So instead of comparing the member objects, this will compare their cell values ! Needless to say, that beyond the performance hit, this is also serious correctness issue, i.e. if there happen to be another account which accidentally has the same value as Flow account, the comparison will say they are equal. So realizing the problems of the above approach, people try to fix it by using property Name of the member, i.e.
|
[Account].CurrentMember.Name = "Flow" |
|
[Account].CurrentMember.UniqueName = "[Account].&[Flow]" |
|
[Account].CurrentMember IS [Account].&[Flow] |