Select语句的总和特定列

时间:2013-07-18 13:37:30

标签: ssas mdx

我对SSAS和MDX很新,并尝试了解它的概念。我需要帮助。

我有一个预订事实表,我想获得特定预订年份和出发年份的市场乘客数量,并且每个出发年份我想要总列数。但无法弄清楚如何将这些列聚合为一个。

这是我现在的代码:

SELECT  {
            (CROSSJOIN([Dep Date].[Calendar Year].&[2012],[Book Date].[Calendar Year].&[2011] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2012],[Book Date].[Calendar Year].&[2012] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2013],[Book Date].[Calendar Year].&[2012] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2013],[Book Date].[Calendar Year].&[2013] ))
        }
        ON 0,  
NON EMPTY [Fact Lead Pax Report].[Mc Major].MEMBERS
ON 1
FROM [Lead Pax Report]
WHERE { [Fact Lead Pax Report].[Res Status].&[A] }

这是我的结果表,我想添加黄色标记所在的总列数:

http://i.stack.imgur.com/5SNAk.png

1 个答案:

答案 0 :(得分:4)

如果要添加另一列来计算特定年份的所有出发次数呢?

例如:

WITH SET [ESC TOURS BY MARKET] AS 
Filter( 
  [Fact Lead Pax Report].[Mc Major].[Mc Major], 
  ([Fact Lead Pax Report].[Mc Major].currentMember.name <> 'AIR') AND ([Fact Lead Pax Report].[Mc Major].currentMember.name <> 'DEFAULT')
)
SELECT  {
            (CROSSJOIN([Dep Date].[Calendar Year].&[2012],[Book Date].[Calendar Year].&[2011] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2012],[Book Date].[Calendar Year].&[2012] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2012],[Book Date].[Calendar Year] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2013],[Book Date].[Calendar Year].&[2012] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2013],[Book Date].[Calendar Year].&[2013] )),
            (CROSSJOIN([Dep Date].[Calendar Year].&[2013],[Book Date].[Calendar Year] ))
        }
        ON 0,  
[ESC TOURS BY MARKET]
ON 1
FROM [Lead Pax Report]
WHERE { [Fact Lead Pax Report].[Res Status].&[A] }