Tuesday, July 29, 2014

Ancestor

The Ancestor functionality allows us to find, parents, grand parents, great grand parents etc.… The number of levels you want to go up can be a number or a dedicated level.
The Ancestor with a level of 1 is the same as the .Parent functionality
Let’s try:
WITH MEMBER
[Measures].[1 Level up] as
    (
        [Measures].[Sales Amount],
        Ancestor
            (
                [Product].[Product Categories].CurrentMember,
                1
            )
    ) , FORMAT_STRING = 'Currency'
MEMBER [Measures].[2 Levels up] as
    (
        [Measures].[Sales Amount],
        Ancestor
            (
                [Product].[Product Categories].CurrentMember,
                2
            )
    ) , FORMAT_STRING = 'Currency'
MEMBER [Measures].[3 Levels up] as
    (
        [Measures].[Sales Amount],
        Ancestor
            (
                [Product].[Product Categories].CurrentMember,
                3
            )
    ) , FORMAT_STRING = 'Currency'
SELECT
{
      [Measures].[Sales Amount]
    , [Measures].[1 Level up]
    , [Measures].[2 Levels up]
    , [Measures].[3 Levels up]
}
ON COLUMNS
,
[Product].[Product Categories].AllMembers
ON ROWS
FROM
[Adventure Works]
This will give us:
image
Have Fun And Till Next Time

No comments:

Post a Comment