MDX:除了我需要特定年份的总销售额

时间:2017-03-15 14:45:43

标签: ssas mdx

- FEB-2008总销售额

SELECT 
{[Measures].[Internet Sales Amount]} ON 0,
{[Date].[Calendar].[Month].&[2008]&[2]} ON 1
FROM [Adventure Works] 
WHERE [Date].[Calendar Year].&[2008]

- $ 47,868.54(FEB第29个月销售额)

SELECT 
{[Measures].[Internet Sales Amount]} ON 0,
{[Date].[Calendar].[Date].&[20080229]} ON 1
FROM [Adventure Works] 
WHERE [Date].[Calendar Year].&[2008]  

- 此处如何在该特定年份中排除FEB月29日SalesAmount

SELECT 
  {[Measures].[Internet Sales Amount]} ON 0, 
 EXCEPT(

    [Date].[Calendar].[Month],
    {[Date].[Calendar].[Date].&[20080229]} 
  )
  ON 1 
FROM [Adventure Works] 
WHERE [Date].[Calendar Year].&[2008] 

enter image description here

1 个答案:

答案 0 :(得分:1)

也许这个:

SELECT 
  [Measures].[Internet Sales Amount] ON 0
FROM [Adventure Works] 
WHERE 
  EXCEPT(
    DESCENDANTS(
      [Date].[Calendar].[Year].&[2008],
      [Date].[Calendar].[Date]
    ),
   [Date].[Calendar].[Date].&[20080229]
  );

或者这个:

WITH 
MEMBER  [Date].[Calendar].[All].[2008minus29feb] AS
AGGREGATE(
  EXCEPT(
    [Date].[Calendar].[Date].MEMBERS,
    [Date].[Calendar].[Date].&[20080229]} 
  )
)
SELECT 
  [Measures].[Internet Sales Amount] ON 0,
  [Date].[Calendar].[All].[2008minus29feb] ON 1 
FROM
  (
  SELECT [Date].[Calendar Year].&[2008]  ON 0
  FROM [Adventure Works] 
  ); 

这样做:

SELECT 
  [Measures].[Internet Sales Amount] ON 0
 ,[Date].[Calendar].[Month] ON 1
FROM 
(
  SELECT 
    Except
    (
      Descendants
      (
        [Date].[Calendar].[Calendar Year].&[2008]
       ,[Date].[Calendar].[Date]
      )
     ,[Date].[Calendar].[Date].&[20080229]
    ) ON 0
  FROM [Adventure Works]
);

结果:

enter image description here