Search code examples
mdxmeasure

Create a measure in MDX for a set of Members


I need something as following:

with member Measures.Test2 as (Measures.Test, {[Assets Monthly].[Disbursed Date].&[2014], [Assets Monthly].[Disbursed Date].&[2015]})
select Measures.Test2 on columns
from databaseX

It works only if I set it with only one member, ex:

with member Measures.Test2 as (Measures.Test, [Assets Monthly].[Disbursed Date].&[2014])

The error that I get in the first case is:

The function expects a string or numeric expression for the argument. A tuple set expression was used.


Solution

  • Against AdvWrks:

    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];
    

    Your script:

    WITH 
      MEMBER Measures.Test2 AS 
        Sum
        (
          {
            [Assets Monthly].[Disbursed Date].&[2014]
           ,[Assets Monthly].[Disbursed Date].&[2015]
          }
         ,Measures.Test
        ) 
    SELECT 
      Measures.Test2 ON COLUMNS
    FROM databaseX;
    

    This is prettier. Created a calculated member on the Date hierarchy and chuck the measures in the WHERE slicer:

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