Search code examples
sql-serverssasmdxolap

[Measures].[First4Days] for each month ON ROWS


How do I replace the following placeholder with a measure that returns the sum of the [Measures].[Internet Sales Amount] for the first 4 days of each month that are on the rows?

WITH 
MEMBER [Measures].[First4Days] AS
  SUM(1) //<<<<<<placeholder
SELECT 
  {
      [Date].[Calendar].[Month].&[2005]&[6]
    : 
      [Date].[Calendar].[Month].&[2008]&[7]
  } ON ROWS
 ,{
    [Measures].[Internet Sales Amount]
   ,[Measures].[First4Days]
  } ON COLUMNS
FROM [Adventure Works];

Solution

  • Your placeholder should be

    Sum(Head([Date].[Calendar].CurrentMember.Children, 4), [Measures].[Internet Sales Amount])
    

    You just take the children of the current month - as coming from the context of the cell, and from this, the first four, and then sum it across Internet Sales Amount.

    Please note that stating rows before columns is not standard MDX, even if Analysis Services accepts it. According to the standard, axes must stated be in ascending order, and rows are Axis(1), while columns are Axis(0).