MDX从日期维度中选择年份列表

时间:2015-09-09 17:22:41

标签: ssas mdx

所以我有一个日期维度,其中一个成员是4位数年份,例如2012年

我对MDX来说还是新手。

我正在使用AdventureWorks 2008 DW查看示例。以下将获得2008年的价值,但我想要一份所有年度会员的价值清单。

WITH MEMBER Measures.ValueColumn as [Date].[Calendar].[July 1, 2008].MemberValue
MEMBER Measures.KeyColumn as [Date].[Calendar].[July 1, 2008].Member_Key
MEMBER Measures.NameColumn as [Date].[Calendar].[July 1, 2008].Member_Name

SELECT {Measures.ValueColumn, Measures.KeyColumn, Measures.NameColumn}  ON 0
from [Adventure Works]

Results:
ValueColumn KeyColumn   NameColumn
7/1/2008    20080701    July 1, 2008

我会更改以获取当前年份和之前5年的年份值列表?

这为我提供了Adventure Works多维数据集中所有Calendar Year成员的列表

SELECT NULL ON COLUMNS,
[Date].[Calendar Year].MEMBERS ON ROWS
FROM [Adventure Works];

结果:

All Periods
CY 2005
CY 2006
CY 2007
CY 2008
CY 2010

这些是成员名称,但我想要他们的值

1 个答案:

答案 0 :(得分:0)

您可以使用currentmember功能来帮助合并您提到的两个脚本:

WITH 
  MEMBER [Measures].[ValueColumn]AS
     [Date].[Calendar Year].CURRENTMEMBER.MemberValue
  MEMBER [Measures].[KeyColumn] AS
     [Date].[Calendar Year].CURRENTMEMBER.Member_Key
  MEMBER [Measures].[NameColumn] AS 
     [Date].[Calendar Year].CURRENTMEMBER.Member_Name
SELECT 
   {
     [Measures].[ValueColumn]
   , [Measures].[KeyColumn]
   , [Measures].[NameColumn]
   }  ON 0
  [Date].[Calendar Year].MEMBERS ON 1
FROM [Adventure Works];

如果您想避开All成员,请将级别添加到表达式[Date].[Calendar Year].MEMBERS ON 1,如下所示:

WITH 
  MEMBER [Measures].[ValueColumn]AS
     [Date].[Calendar Year].CURRENTMEMBER.MemberValue
  MEMBER [Measures].[KeyColumn] AS
     [Date].[Calendar Year].CURRENTMEMBER.Member_Key
  MEMBER [Measures].[NameColumn] AS 
     [Date].[Calendar Year].CURRENTMEMBER.Member_Name
SELECT 
   {
     [Measures].[ValueColumn]
   , [Measures].[KeyColumn]
   , [Measures].[NameColumn]
   }  ON 0
  [Date].[Calendar Year].[Calendar Year].MEMBERS ON 1
FROM [Adventure Works];