0
SELECT  
  [Measures].[Internet Sales Amount] ON COLUMNS  
 ,Tail  
  (  
    [Date].[Calendar Year].[Calendar Year].MEMBERS  
   ,2  
  ) ON ROWS  
FROM [Adventure Works];  

以上 MDX 查询给我的输出为:

年份 互联网销售额

2003 年 9,791,060.30 美元

2004 年 9,770,899.74 美元

我了解这个查询是如何工作的,但我想在一个多维数据集中创建计算度量,它总是给我底部 2 年的总和。这该怎么做?我是 SSAS 的新手。我擅长设计简单的度量和维度,但在使用 MDX 时,我大多陷入困境。

PS:我尝试使用 TopCount、BottomCount 等,但在这里我想按“年份”排序,这是一个维度。

任何帮助,将不胜感激。

谢谢,

招架

4

1 回答 1

1

以下查询计算 Date 维度最近 2 年总和的度量:

WITH
MEMBER [Measures].[Sales from the last 2 Years]
    AS Aggregate( Tail( [Date].[Calendar Year].[Calendar Year].Members, 2)
                , [Measures].[Internet Sales Amount]
                )

SELECT { [Measures].[Sales from the last 2 Years]
       } ON COLUMNS
     , { Tail( [Date].[Calendar Year].[Calendar Year].Members, 2)
       } ON ROWS
    FROM [Adventure Works]

其他有趣的查询,将计算每年和以前的总和的度量:

WITH
MEMBER [Measures].[Sales from 2 years]
    AS Aggregate( { [Date].[Calendar Year].CurrentMember.PrevMember
                  : [Date].[Calendar Year].CurrentMember }
                , [Measures].[Internet Sales Amount]
                )

SELECT { [Measures].[Internet Sales Amount]
       , [Measures].[Sales from 2 years]
       } ON COLUMNS
     , NON EMPTY
       { [Date].[Calendar Year].[Calendar Year]
       } ON ROWS
    FROM [Adventure Works]

It does a sum, because the aggregation type of the measure [Measures].[Internet Sales Amount] is Sum, and the Aggregate function aggregates according to the measure's aggregation type.

MDX is a hard topic to grasp; if you're starting out, I recommend you read the book MDX Solutions, 2nd edition.

于 2012-04-13T15:14:10.703 回答