Reputation: 2441
I am creating some tool to dynamically generating MDX queries. In a part of the query I am generating I need to check whether an expression is a member expression or tuple expression and apply different logic on it. Does anyone have any clue about how I can check the MDX expression type at run time by just using MDX?
Upvotes: 1
Views: 351
Reputation: 13315
To know the exact type of an MDX expression, you would have to write an MDX parser (at least for the expressions that can appear).
There are some rules: something like (x, y)
is probably a tuple; and the result of all methods that return a tuple (like StrToTuple
, Root
, or Item
, the latter only if applied to a set) is a tuple, and the result of all methods that return a member (like Ancestor
or DefaultMember
, but also Item
if applied to a tuple) is a member. See http://msdn.microsoft.com/en-us/library/ms145970.aspx for a list of functions classified by type. But you see already the difficulty of the Item
method which can either deliver a tuple, or a member, depending on context.
And I would not think that you can easily write an MDX statement that tests the type, as Analysis Services uses automatic type casting which converts a member to a tuple whenever the context needs one.
The best approach from my point of view would be to use syntax that allows both a member and a tuple being used, and to avoid having to know the type.
One approach that could work as well without need to explicitly checking for data type, but just checking if some construct is valid or not would be using the VBA function IsError
as follows:
IIf(IsError(x.Level, <something avoiding the Level function>, <use x.Level>)
Upvotes: 1