MDX平均功能指望

时间:2014-12-17 18:59:10

标签: ssis mdx cube

我偶然发现了一个我无法解决的问题。对于我的学术项目,我有一个代表航空公司数据仓库的立方体。在这家航空公司,乘客填写了5个问题的qustionnaire,评估从1到10的航班的各个方面

我被要求写一个MDX查询,以显示他们的整体航班等级(五个等级的平均值),具体取决于他们所在的班级。

这是我的疑问:

 WITH 
  MEMBER [Average Grade1] AS 
    [Measures].[Grade1] / [Measures].[Flight Count] 
  MEMBER [Average Grade2] AS 
    [Measures].[Grade2] / [Measures].[Flight Count] 
  MEMBER [Average Grade3] AS 
    [Measures].[Grade3] / [Measures].[Flight Count] 
  MEMBER [Average Grade4] AS 
    [Measures].[Grade4] / [Measures].[Flight Count] 
  MEMBER [Average Grade5] AS 
    [Measures].[Grade5] / [Measures].[Flight Count] 
  MEMBER [Average] AS 
      (
            [Measures].[Average Grade1] + [Measures].[Average Grade2]
          + 
            [Measures].[Average Grade3]
        + 
          [Measures].[Average Grade4]
      + 
        [Measures].[Average Grade5]
      )
    / 5 
SELECT 
  {
    [Measures].[Average Grade1]
   ,[Measures].[Average Grade2]
   ,[Measures].[Average Grade3]
   ,[Measures].[Average Grade4]
   ,[Measures].[Average Grade5]
   ,[Measures].[Average]
  } ON COLUMNS
 ,{[Junk].[Class].Children} ON ROWS
FROM [Airline];

它给出了错误的结果,因为平均值在按类进行实际分组之前计算,这就是为什么所有类都显示相同结果的原因。 谁能告诉我如何得到我想要的结果?

1 个答案:

答案 0 :(得分:1)

正如mmarie所提到的,这通常是获得平均值的方法:

WITH 
  MEMBER [Average Grade1] AS 
    [Measures].[Grade1] / [Measures].[Flight Count] 
  MEMBER [Average Grade2] AS 
    [Measures].[Grade2] / [Measures].[Flight Count] 
  MEMBER [Average Grade3] AS 
    [Measures].[Grade3] / [Measures].[Flight Count] 
  MEMBER [Average Grade4] AS 
    [Measures].[Grade4] / [Measures].[Flight Count] 
  MEMBER [Average Grade5] AS 
    [Measures].[Grade5] / [Measures].[Flight Count] 
  MEMBER [Average] AS 
      (
            [Measures].[Grade1] + [Measures].[Grade2]
          + 
            [Measures].[Grade3]
        + 
          [Measures].[Grade4]
      + 
        [Measures].[Grade5]
      )
    / [Measures].[Flight Count]
SELECT 
  {
    [Measures].[Average Grade1]
   ,[Measures].[Average Grade2]
   ,[Measures].[Average Grade3]
   ,[Measures].[Average Grade4]
   ,[Measures].[Average Grade5]
   ,[Measures].[Average]
  } ON COLUMNS
 ,{[Junk].[Class].Children} ON ROWS
FROM [Airline];

如果某个度量没有连接到MDX脚本的上下文,那么您将重复该答案。因此,如果您使用的度量没有连接到上下文,即[Junk].[Class].Children,那么您将根据默认成员评估进行重复。

尝试更换[Junk].[Class].Children以获取与度量[Measures].[Grade1][Measures].[Flight Count]

100%相关的其他维度