【问题标题】:MDX case statements in WHERE clauseWHERE 子句中的 MDX case 语句
【发布时间】:2017-08-15 21:26:58
【问题描述】:

我在 Adventure Works 中玩弄 MDX。我尝试不同的事情来练习(所以我知道可能有更好的方法来使用日期层次结构来实现这一点,但我正在尝试使用月份名称而不是特定的月份和年份名称(如果这有意义的话). 我想要做的是使用一个 case 语句,它会滞后于我的 2 个集合,但不会滞后于其他 2 个。换句话说,我希望它返回 2010 年第一季度的值(7 月,8 月,Sept) 和 Q2 (Oct, Nov, Dec) 设置,但 2011 年 Q3(Jan,Feb,Mar) 和 Q4 设置 (Apr, May, June) 的值。这就是我所拥有的,但案例陈述只是给出了滞后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]措施

【问题讨论】:

    标签: case where mdx adventureworks


    【解决方案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];
    

    【讨论】:

    • 好的。我明白你的意思了。那讲得通。我什至都没有意识到要这样做。
    • 很高兴它有帮助 - 你知道一旦你有了这个入口点,你就可以使用 strToMember 或 StrToSet 以便客户端参数可以输入 mdx
    猜你喜欢
    • 2014-09-08
    • 2020-03-26
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    相关资源
    最近更新 更多