| Chris's profileChris Webb's BI BlogBlogLists | Help |
|
7/28/2006 Alternative Calculated Member Definition SyntaxNow that BOL is being overhauled my list of things that it misses out is getting shorter and shorter...
Anyway, did you know that there are two syntaxes you can use to define calculated members in your MDX Script? There's good old CREATE MEMBER, which Visual Studio itself uses, and there's also the more concise CREATE syntax. Here's the BNF: CREATE [HIDDEN] [<parent>.]<name> = <expression> Nothing special about it really; just note that if [<parent>] is missing it creates the member on the Measures dimension, and if you need to specify properties such as FORMAT_STRING etc for the calc then you need to either use assignments or edit the DDL of the MDX Script.
The only person I've ever seen use this syntax is Mosha in a few of his blog posts. I don't know why it was introduced apart from the fact that is is more concise; I do know that in one instance it behaves differently from CREATE MEMBER. Take the following MDX Script an put it onto the Adventure Works cube:
--an example of the old syntax CREATE MEMBER CURRENTCUBE.[MEASURES].[Old Style] AS 1,VISIBLE = 1 ;--an example of the new syntax CREATE [New Style] = 1;
SCOPE ([Date].[Day Name].&[1]); THIS=100;END SCOPE;SCOPE ([Date].[Day Name].&[2]); THIS=100;END SCOPE;CREATE MEMBER CURRENTCUBE.[MEASURES].[Old Style 2] AS 1,VISIBLE = 1 ;
If you run the following query:
select {[Measures].[Old Style], [Measures].[New Style], [Measures].[Old Style 2]} on 0,[Date].[Day Name].members on 1 from [adventure works]
You'll see that the cell for [Old Style 2] and [Sunday] doesn't contain the value 100, whereas the cell for [Old Style 2] and [Monday] does. When I found out about this I was told that it was a bug, but was also the result of mixing old style calculated member definitions with MDX Script assignments, and that if you were going to be doing assignments in your cube then you should always use the new style calculated member definition syntax. So perhaps it is a good idea to use the new style syntax all the time - although I know in my case, old habits will die hard. Comments (4)
TrackbacksThe trackback URL for this entry is: http://cwebbbi.spaces.live.com/blog/cns!7B84B0F2C239489A!823.trak Weblogs that reference this entry
|
|
|