问题
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