Ssas 统计过去三个月的发票数量?

Ssas 统计过去三个月的发票数量?,ssas,mdx,olap,ssas-2012,Ssas,Mdx,Olap,Ssas 2012,谢谢大家。这是我的MDX查询,返回2015年3月生成的发票数量,效果非常好 WITH SET [mySet] AS [Customer].[Store Group].[Store Group] * {[Measures].[Sales #]} MEMBER [Measures].[setDistCount] AS DistinctCount([mySet]) SELECT { [Measures].[Sales #] } ON 0 ,NON E

谢谢大家。这是我的MDX查询,返回2015年3月生成的发票数量,效果非常好

 WITH 
  SET [mySet] AS 
    [Customer].[Store Group].[Store Group] * {[Measures].[Sales #]} 
  MEMBER [Measures].[setDistCount] AS 
    DistinctCount([mySet]) 
SELECT 
  {
  [Measures].[Sales #]
  } ON 0
 ,NON EMPTY 
    [Customer].[Store Group].[Store Group] ON 1
FROM 
(
  SELECT 
    {[Calendar].[Month].[March 2015]} ON 0
  FROM [F1_SalesBI]
);
输出如下所示:

            Sales #
Store 1     156
Store 2      56
Store 3     546
...
Store 10     69
但我希望得到这样的报告:

            March     February     January
Store 1     156       656          145
Store 2      56        89           41
Store 3     546       215          215
...
Store 10     69        69           96
SELECT 
  Tail([Calendar].[Month].[Month].members,3) ON 0 //<< I've assumed this is ok but you may need to use [Calendar].[Month].members
 ,NON EMPTY 
    [Customer].[Store Group].[Store Group] ON 1
FROM [F1_SalesBI]
WHERE [Measures].[Sales #];

对于我想要的输出,我应该如何查询?请帮帮我

以这种方式创建集合

WITH SET Last3Months AS
GENERATE
(
    [Calendar].[Month].[March 2015],    
    {[Calendar].[Month].CURRENTMEMBER.LAG(2):[Calendar].[Month].CURRENTMEMBER}
)
这将创建一组包括当前月份在内的最近3个月(在集合的定义中提供)

然后,下面的查询将得到您所需要的

SELECT 
  Last3Months ON 0

 ,NON EMPTY 
    [Customer].[Store Group].[Store Group].MEMBERS ON 1

 FROM [F1_SalesBI]

WHERE {[Measures].[Sales #]}

Generate
看起来情况过于复杂,可能只需要简单一点:

SELECT 
  {
   [Calendar].[Month].[March 2015],
   [Calendar].[Month].[February 2015],
   [Calendar].[Month].[January 2015],
  } ON 0
 ,NON EMPTY 
    [Customer].[Store Group].[Store Group] ON 1
FROM [F1_SalesBI]
WHERE [Measures].[Sales #];
要使此动态化,使其仅显示多维数据集中的最后三个月,请使用如下
Tail
功能:

            March     February     January
Store 1     156       656          145
Store 2      56        89           41
Store 3     546       215          215
...
Store 10     69        69           96
SELECT 
  Tail([Calendar].[Month].[Month].members,3) ON 0 //<< I've assumed this is ok but you may need to use [Calendar].[Month].members
 ,NON EMPTY 
    [Customer].[Store Group].[Store Group] ON 1
FROM [F1_SalesBI]
WHERE [Measures].[Sales #];
选择

Tail([Calendar].[Month].[Month].[Month].[Month].[Month].[Month].[Month]成员,3)在0//Error,“月份层次结构已经出现在Axis0轴上。”@Sourav_Agasti为什么要麻烦
生成
?在切片器中有月份,而一个轴是不可能的。子选择中的月份会导致集合中的
[All]
成员,因此同样不适合!因此,最后使用了
GENERATE
@Sourav_Agasti,您也可以使用
[Calendar][Month][2015年3月].LAG(2):[Calendar][Month][2015年3月]
更正!可以用。它现在很有魅力了?但是这个度量值
[Measures].[setDistCount]
不包括在
WITH
子句之外的任何地方?是的,不应该在那里。这不是必需的,但会起作用。如果明确提及成员,则不需要子选择。2.对于一个典型的场景,人们可能希望用其他月份代替三月,这需要做大量的工作。3.因此不适合报告场景。@Sourav_Agasti-同意sub-select在sub-select中进行游行将范围缩小为游行。所以实际上只有一个月的时间。你的解决方案在我看来行不通guess@Sourav_Agasti你怎么知道的?它可能是
[日历].[月份].[calmnth]。成员
正确。我的意思是,从句法上说,这很好。