获取过去三个月的发票数量?

时间:2015-04-01 11:56:26

标签: 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 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

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

2 个答案:

答案 0 :(得分:1)

以这种方式创建集合

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 #]}

答案 1 :(得分:1)

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函数,如下所示:

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 #];