Thursday, February 17, 2011

mdx: query to override parent value with last child value

This query overrides the value of parent with the value of last child.

WITH  

MEMBER LevelOrdinal AS
       [Date].[Calendar].currentmember.level.ordinal
MEMBER LevelName AS
       [Date].[Calendar].currentmember.level.name
      
MEMBER [Measures].[ResellerOrderCountLastPeriod] AS
       (
              CLOSINGPERIOD(
                     [Date].[Calendar].[Month],
                     ANCESTOR(
                           [Date].[Calendar].CURRENTMEMBER,0
                     )
              )
              ,[Measures].[Reseller Order Count]
       ),
Back_Color =
       case when [Date].[Calendar].CURRENTMEMBER.level.ordinal=1 then RGB(0,255,255)
               when [Date].[Calendar].CURRENTMEMBER.level.ordinal=2 then RGB(125,255,255)
               when [Date].[Calendar].CURRENTMEMBER.level.ordinal=3 then RGB(200,255,255)
       else NULL
       end

             
SELECT
{
       LevelOrdinal,
       LevelName,
       [Measures].[Reseller Order Count],
       [Measures].[ResellerOrderCountLastPeriod]
} ON 0,
NONEMPTY
(
       EXCEPT(
              DESCENDANTS([Date].[Calendar].[Calendar Year],,SELF_AND_AFTER),
              [Date].[Calendar].[Date]
       )
       ,[Measures].[ResellerOrderCountLastPeriod]
)
ON 1
FROM
       [Adventure Works]
--WHERE
       --[Date].[Calendar Year].&[2001]
cell properties formatted_value, back_color

--I have added except to exclude the date level.



Result

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

LinkWithin

Related Posts with Thumbnails