WHERE 子句中的 MDX case 语句

MDX case statements in WHERE clause

我正在 Adventure Works 中玩 MDX。我尝试不同的方法来练习(所以我知道可能有更好的方法来使用日期层次结构来实现这一点,但我正在尝试使用月份名称而不是特定的月份和年份名称(如果这有意义的话) )。我想要做的是使用一个 case 语句,它会滞后于我的 2 个集合,但不会滞后于其他 2 个。换句话说,我希望它 return 我的 Q1 的 2010 年值(7 月、8 月、9 月)和第 2 季度(10 月、11 月、12 月)集,但 2011 年的值为第 3 季度(1 月、2 月、3 月)和第 4 季度集(4 月、5 月、6 月)。这就是我所拥有的,但情况语句只为所有延迟 1。所以我了解它是如何工作的,但似乎无法理解如何 return 如上所述每个集合的不同值。

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]措施

我更倾向于将不同切片的逻辑放在您的 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];