Ever a need for CurrentMember.Item(0)

白昼怎懂夜的黑 提交于 2021-02-10 16:59:37

问题


The custom measure in the following is taken from the book MDX Cookbook (Tomislav Piasevoli):

WITH 
  MEMBER [Internet Sales PP] AS 
    Sum
    (
      Generate
      (
        {
            [Date].[Calendar].[Date].&[20080105]
          : 
            [Date].[Calendar].[Date].&[20080125]
        }
       ,{
          ParallelPeriod
          (
            [Date].[Calendar].[Calendar Year]
           ,1
           ,[Date].[Calendar].CurrentMember.Item(0)
          )
        }
      )
     ,[Measures].[Internet Sales Amount]
    ) 
SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Internet Sales PP]
  } ON 0
 ,[Product].[Color].MEMBERS ON 1
FROM [Adventure Works];

What purpose does the item(0) serve?

My understanding, which is probably wrong is

  • <set>.item(0) gives us first tuple in set
  • <tuple>.item(0) gives us first member in tuple

So what is the point of <member>.item(0)?


回答1:


Refer this excellent article on the topic.

To sum it up, when we are doing a .ITEM(0) on a member, that member is implicitly converted to a tuple. So, .ITEM(0) does not really serve any purpose other than returning the member itself.




回答2:


I would assume this is a typo or a copy paste error. At least in the official Microsoft MDX reference, there are only the two Item() versions that you mention.

And this does not cause an error, as there are some implicit type conversions:

  • If you have a member and need a tuple for the current expression, AS implicitly builds a one-member tuple from the member. Which is what takes place here presumably, when applying Item(0) to a member.
  • If you have a one member tuple and need a member for the current expression, AS implicitly applies Item(0).
  • There are similar implicit conversions from tuple and level to set, from tuple to scalar value, from dimension to hierarchy, and from hierarchy to member.


来源:https://stackoverflow.com/questions/26802526/ever-a-need-for-currentmember-item0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!