WHERE子句

时间:2017-07-30 13:45:36

标签: case where mdx adventureworks

我在Adventure Works中玩MDX。我尝试不同的东西只是练习(所以我知道可能有更好的方法来使用日期层次来实现这一点,但我尝试使用月份名称而不是具体的月份和年份名字(如果有意义的话)。我试图做的是使用一个案例陈述,这个陈述会滞后于我的2套,但没有滞后于另外2个。换句话说,我希望它能够回归2010年我的第一季度(7月,8月,9月)和第2季度(10月,11月,12月)的价值,但是第3季度(1月,2月,3月)和第4季度(4月,5月,6月)的2011年价值。这里'我所拥有的,但是案例陈述只给了所有人的滞后1。所以我理解它是如何工作的,但似乎无法理解如何返回不同的值每组如上所述。

WITH 
    SET [Q1 Combined] AS {
    [Date].[Month of Year].&[7],
    [Date].[Month of Year].&[8],
    [Date].[Month of Year].&[9]   }

SET [Q2 Combined] AS {
    [Date].[Month of Year].&[10],
    [Date].[Month of Year].&[11],
    [Date].[Month of Year].&[12]   }

SET [Q3 Combined] AS {
    [Date].[Month of Year].&[1],
    [Date].[Month of Year].&[2],
    [Date].[Month of Year].&[3]   }

SET [Q4 Combined] AS {
    [Date].[Month of Year].&[4],
    [Date].[Month of Year].&[5],
    [Date].[Month of Year].&[6]   }

MEMBER [Date].[Month of Year].[FY Q1 Fix] AS Aggregate([Q1 Combined])
MEMBER [Date].[Month of Year].[FY Q2 Fix] AS Aggregate([Q2 Combined])
MEMBER [Date].[Month of Year].[FY Q3 Fix] AS Aggregate([Q3 Combined])
MEMBER [Date].[Month of Year].[FY Q4 Fix] AS Aggregate([Q4 Combined])

SELECT
[Measures].[Internet Sales Amount] ON COLUMNS,

{
[Date].[Month of Year].[FY Q1 Fix],
[Date].[Month of Year].[FY Q2 Fix],
[Date].[Month of Year].[FY Q3 Fix],
[Date].[Month of Year].[FY Q4 Fix]} ON ROWS
                                                                                            } ON ROWS


FROM [Adventure Works]

WHERE **I WANT TWO DIFFERENT SLICES**

换句话说,我想:

[FY Q1 Fix]和[FY Q2 Fix]将被切片并显示[Date]。[2010]措施

[FY Q3 Fix]和[FY Q4 Fix]切片并显示[Date]。[2011]措施

1 个答案:

答案 0 :(得分:1)

我更倾向于将不同切片的逻辑放在WITH子句而不是WHERE子句中。因此,在下面你可以看到有一个硬编码的年份,然后我使用滞后对两个季度集:

WITH 
  SET [targetYear] AS 
    [Date].[Fiscal Year].&[2008] 
  SET [Q1 Combined] AS 
      {
        [Date].[Month of Year].&[7]
       ,[Date].[Month of Year].&[8]
       ,[Date].[Month of Year].&[9]
      }
    * 
      [targetYear].Item(0) 
  SET [Q2 Combined] AS 
      {
        [Date].[Month of Year].&[10]
       ,[Date].[Month of Year].&[11]
       ,[Date].[Month of Year].&[12]
      }
    * 
      [targetYear].Item(0) 
  SET [Q3 Combined] AS 
      {
        [Date].[Month of Year].&[1]
       ,[Date].[Month of Year].&[2]
       ,[Date].[Month of Year].&[3]
      }
    * 
      [targetYear].Item(0).Lag(1) 
  SET [Q4 Combined] AS 
      {
        [Date].[Month of Year].&[4]
       ,[Date].[Month of Year].&[5]
       ,[Date].[Month of Year].&[6]
      }
    * 
      [targetYear].Item(0).Lag(1) 
  MEMBER [Date].[Month of Year].[FY Q1 Fix] AS 
    Aggregate([Q1 Combined]) 
  MEMBER [Date].[Month of Year].[FY Q2 Fix] AS 
    Aggregate([Q2 Combined]) 
  MEMBER [Date].[Month of Year].[FY Q3 Fix] AS 
    Aggregate([Q3 Combined]) 
  MEMBER [Date].[Month of Year].[FY Q4 Fix] AS 
    Aggregate([Q4 Combined]) 
SELECT 
  [Measures].[Internet Sales Amount] ON COLUMNS
 ,{
    [Date].[Month of Year].[FY Q1 Fix]
   ,[Date].[Month of Year].[FY Q2 Fix]
   ,[Date].[Month of Year].[FY Q3 Fix]
   ,[Date].[Month of Year].[FY Q4 Fix]
  } ON ROWS
FROM [Adventure Works];