Tuesday, 19 November 2013

Getting YTD values in MDX

"Year To Date" means aggreatated value of a particular measure from begining date to specified date.

Example 1:
  •  WITH MEMBER [Measures].[ytdOrderQuantityFor2007] AS
        SUM(
            YTD([Date].[Calendar].CURRENTMEMBER)
                ,[Measures].[Order Quantity]
        )
    SELECT
        {[Measures].[Order Quantity],[Measures].[ytdOrderQuantityFor2007]} ON COLUMNS,
        NON EMPTY (   
                    [Product].[Category].Children
                    *               
                    [Date].[Calendar].MEMBERS
                       
        ) ON ROWS
    FROM   
    (
        SELECT {[Date].[Calendar].[Calendar Year].&[2008]}  ON COLUMNS
        FROM [Adventure Works]
    )
  


















Example 2:

  • Query below return the sum of "Order Quanity" from Jan 2007 to August 2007 by making use of YTD function through member "First8MonthsCY2007".

  •  WITH MEMBER [Date].[Calendar].[First8MonthsCY2007] AS
        Aggregate(
            YTD([Date].[Calendar].[Month].[August 2007])
        )
    SELECT
        {[Date].[Calendar].[First8MonthsCY2007]
         ,[Date].[Calendar].[Month].&[2007]&[1]:[Date].[Calendar].[Month].&[2007]&[8]
        } ON COLUMNS,
        [Product].[Category].Children ON ROWS
    FROM
        [Adventure Works]
    WHERE
        [Measures].[Order Quantity]








Example 3:

  • WITH MEMBER [Measures].[ytdOrderQuantityFor2007] AS
        SUM(
            YTD([Date].[Calendar Weeks].CURRENTMEMBER)
                ,[Measures].[Order Quantity]
        )
    SELECT
        {[Measures].[Order Quantity],[Measures].[ytdOrderQuantityFor2007]} ON COLUMNS,
        NON EMPTY (  
                    [Product].[Category].Children
                    *  
                    [Date].[Calendar Weeks].[Calendar Week].MEMBERS           
                      
        ) ON ROWS
    FROM  
    (
        SELECT {[Date].[Calendar].[Calendar Year].&[2008]}  ON COLUMNS
        FROM [Adventure Works]
    )


No comments:

Post a Comment