Search code examples
mdxmeasure

Creating a measure by filtering out a set from an existing measure


I am trying to implement something as follows:

WITH MEMBER Measures.Test2 AS 
Sum
(
  {
    [Date].[Calendar].[Calendar Year].&[2006]
   ,[Date].[Calendar].[Calendar Year].&[2007]
  }
 ,[Measures].[Internet Sales Amount]
) 
SELECT Measures.Test2 ON COLUMNS 
FROM [Adventure Works];

But i want the new measure Test2 to be sliceable according to the Calendar Year dimension. So i want something like

SELECT {Measures.Test2} ON 0,
{[Date].[Calendar].[Calendar Year].[Calendar Year].MEMBERS} ON 1 
FROM [Adventure Works];

This is giving the same value for both the years 2006 and 2007.

In essence i want to create a member by taking a subset of an existing measure and then using it for further calculations


Solution

  • This script is not valid mdx:

    SELECT (Measures.Test2,[Date].[Calendar].[Calendar Year].[Calendar Year] ON COLUMNS 
    FROM [Adventure Works];
    

    You have a single ( before Measures.
    Also you look like you're about to add a tuple ON COLUMNS which is not allowed. Only sets are allowed on rows and columns:

    SELECT 
    {Measures.Test2} ON 0,
    {[Date].[Calendar].[Calendar Year].[Calendar Year].MEMBERS} ON 1
    FROM [Adventure Works];
    

    Try the following:

    WITH 
      MEMBER Measures.Test2 AS 
        Sum
        (
          Intersect
          (
            {[Date].[Calendar].CurrentMember}
           ,{
              [Date].[Calendar].[Calendar Year].&[2006]
             ,[Date].[Calendar].[Calendar Year].&[2007]
            }
          )
         ,[Measures].[Internet Sales Amount]
        ) 
    SELECT 
      [Measures].test2 ON COLUMNS
     ,{[Date].[Calendar].[Calendar Year].MEMBERS} ON ROWS
    FROM [Adventure Works];
    

    The above returns this:

    enter image description here

    Or maybe all you want is a subselect:

    SELECT 
      [Measures].[Internet Sales Amount] ON COLUMNS
     ,{[Date].[Calendar].[Calendar Year].MEMBERS} ON ROWS
    FROM 
    (
      SELECT 
        {
          [Date].[Calendar].[Calendar Year].&[2006]
         ,[Date].[Calendar].[Calendar Year].&[2007]
        } ON 0
      FROM [Adventure Works]
    );