在命名计算中到目前为止的整数键

时间:2017-06-04 07:47:22

标签: ssas integer-overflow

尝试在SSAS中从整数键到Quarter进行命名计算。 IntegerDateKey下面:

  SalesDateKey
   20100101
   20100101
   20100101
   20100102
   20100102
   20100102
   20100102

这不起作用,无论我怎么做,我都无法让它发挥作用。

  CONVERT(char(4), YEAR(SalesDateKey))+
  CASE
      WHEN MONTH(SalesDateKey) BETWEEN 1 AND 3 THEN 'Q1'
      WHEN MONTH(SalesDateKey) BETWEEN 4 AND 6 THEN 'Q2'
      WHEN MONTH(SalesDateKey) BETWEEN 7 AND 9 THEN 'Q3'
      ELSE 'Q4'
  END

非常感谢任何帮助。请在SSAS中的命名计算中测试您的发现。

1 个答案:

答案 0 :(得分:0)

想出来!

CAST(DATEPART(YEAR, CAST(CAST(SalesDateKey AS char(8)) AS DateTime)) AS 
VARCHAR(4)) + ' - ' +
CASE
   WHEN Month(CAST(CAST(SalesDateKey AS CHAR(8)) AS DATE)) BETWEEN 1 AND 3 
   THEN 'Q1'
   WHEN Month(CAST(CAST(SalesDateKey AS CHAR(8)) AS DATE)) BETWEEN 4 AND 6 
   THEN 'Q2'
   WHEN Month(CAST(CAST(SalesDateKey AS CHAR(8)) AS DATE)) BETWEEN 7 AND 9 
   THEN 'Q3'
   ELSE 'Q4'
END