我在 SSAS 服务器中使用 MDX 查询。
我想在单个 MDX 中获取特定日期范围(动态变化)的当前年份(01/01/2002 - 31/12/2002)和上一年(01/01/2001 - 31/12/2001)数据根据使用的度量和维度进行查询。这里 [Measures].[Sales Amount Quota] 是度量字段,[Employee].[Title] 是维度字段。
结果必须包含 1 个维度列、当前年份的 1 个度量列和上一年的另外 1 个度量列。
我准备了一个查询,但它不起作用,请在下面找到查询:
WITH
MEMBER [Measures].[current year data] AS
CASE WHEN CDate([Hire Date].CurrentMember.MemberValue) >= CDate('2002-01-01') AND CDate([Hire Date].CurrentMember.MemberValue) <= CDate('2002-12-31') THEN [Measures].[Sales Amount Quota] ELSE null END
MEMBER [Measures].[previous year data] AS CASE WHEN CDate([Hire Date].CurrentMember.MemberValue) >= CDate('2001-01-01') AND CDate([Hire Date].CurrentMember.MemberValue) <= CDate('2001-12-31') THEN [Measures].[Sales Amount Quota] ELSE null END
SELECT{
[Measures].[current year data],[previous year data]} ON COLUMNS ,NONEMPTY(((Order((([Employee].[Title].[Title].ALLMEMBERS)),[Employee].[Title].CurrentMember.Member_Caption,ASC))),
{[Measures].[current year data],[previous year data]}) ON ROWS FROM [Sales Targets] CELL PROPERTIES VALUE, FORMATTED_VALUE, FORMAT_STRING
但是当我在 order 子句中使用 date 字段时,要求部分实现了。
WITH
MEMBER [Measures].[current year data] AS
CASE WHEN CDate([Hire Date].CurrentMember.MemberValue) >= CDate('2002-01-01') AND CDate([Hire Date].CurrentMember.MemberValue) <= CDate('2002-12-31') THEN [Measures].[Sales Amount Quota] ELSE null END
MEMBER [Measures].[previous year data] AS
CASE WHEN CDate([Hire Date].CurrentMember.MemberValue) >= CDate('2001-01-01') AND CDate([Hire Date].CurrentMember.MemberValue) <= CDate('2001-12-31') THEN [Measures].[Sales Amount Quota] ELSE null END
SELECT{
[Measures].[current year data],[Measures].[previous year data]} ON COLUMNS ,NONEMPTY(((Order((([Employee].[Title].[Title].ALLMEMBERS)),[Employee].[Title].CurrentMember.Member_Caption,ASC))*
(Order((([Employee].[Hire Date].[Hire Date].ALLMEMBERS)),[Employee].[Hire Date].CurrentMember.Member_Caption,ASC))),
{[Measures].[current year data],[Measures].[previous year data]}) ON ROWS FROM [Sales Targets] CELL PROPERTIES VALUE, FORMATTED_VALUE, FORMAT_STRING
在结果中,维度值必须被分组,度量值也被聚合
主要目标需要使用 MDX 查询中动态日期范围的周期逻辑来比较数据
谁能帮我解决这个问题?