SSAS Cube计算的成员总数错误

时间:2015-01-08 13:42:25

标签: mdx cube cross-join ssas-2008

我正在学习这份工作。我在每张床上都有一张桌子。我想计算床的使用百分比。我在SSAS 2008中的多维数据集中创建了计算成员

CREATE MEMBER CURRENTCUBE.[Measures].UtilisationPercent
 AS avg( 
    crossjoin(
      descendants([bedlabel].[hierarchy].currentmember, [Bedlabel].[Bedlabel])
     ,descendants([Date].[date].currentmember, [Date].[Day])
    )
    ,[Measures].[Utilisation Mins]
   ) 
/ (24*60), 
FORMAT_STRING = "Percent", 
NON_EMPTY_BEHAVIOR = { [Utilisation Mins] }, 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Bedstay'  ; 

如果我按年/月或病房/床铺切片,这实际上工作正常。

但是多维数据集浏览器中显示的总利用率是错误的。如何控制利用总量的计算方式?我能否以交叉连接比叶子更高的水平工作的方式创建计算成员?

January 2011    Utilisation %
  • Bed1 98.86%
  • Bed2 88.38%
  • Bed3 82.63%
  • Bed4 94.67%
  • Bed5 85.82%
  • Bed6 93.53%
  • Bed7 78.78%
  • Bed8 85.43%
  • Bed9 91.16%
  • Bed10 90.93%
  • Bed11 92.00%
  • 总计894.35%< ---这太错了。

- 在MEZ的评论之后添加

好的,谢谢你的提示。我在这之后尝试了范围分配

SCOPE([Measures].[Utilisation Percentage]);     
    SCOPE([Date].[Date].MEMBERS);     
        SCOPE([bedlabel].[hierarchy].MEMBERS);     
            THIS = [Measures].[Utilisation Mins] / 
                    (60*24
                    * count(descendants([bedlabel].[hierarchy].currentmember, [Bedlabel].[Bedlabel])) 
                    * count(descendants([Date].[date].currentmember, [Date].[Day]))) ;     
        END SCOPE;     
    END SCOPE;     
END SCOPE;  

我得到了与crossjoin方法相同的结果。 AS2008在作用域分配结果和旧的交叉连接方法之间没有区别?它仍然以超现实的数字总计,我无法解释。

3 个答案:

答案 0 :(得分:1)

这是Sourav_Agasti建议的排列,它现在有效。我认为avg + nonmptycrossjoin比avg + coalesceempty工作得更好。

CREATE MEMBER CURRENTCUBE.[Measures].UtilisationPercent
 AS avg( nonemptycrossjoin(
       descendants([bedlabel].[hierarchy].currentmember,[bedlabel].[hierarchy].[Bedlabel])
       ,descendants([Date].[date].currentmember,[date].[date].[day]))
       , [Measures].[Utilisation Mins]/ (24*60)), 
FORMAT_STRING = "Percent", 
NON_EMPTY_BEHAVIOR = { [Utilisation Mins] }, 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Bedstay'; 

根据MEZ的建议,这也有效。

SCOPE([Measures].[Utilisation Percentage]);
  scope ([bedlabel].[hierarchy].members);
      scope ([date].[date].members);      
          this = avg( nonemptycrossjoin(
            descendants([bedlabel].[hierarchy].currentmember,[bedlabel].[hierarchy].[Bedlabel])
            ,descendants([Date].[date].currentmember,[date].[date].[day]))
            , [Measures].[Utilisation Mins]/ (24*60)) ;
          non_empty_behavior (this) = [Utilisation Mins] ;
      end scope;
  end scope;
END SCOPE; 

与AS2000的区别在于我只需要这样做,并在计算的度量上指定average作为聚合方法。我也没有多层次结构。语法对我来说似乎更简单。

avg(nonemptycrossjoin(descendants([Unit].currentmember,[Unit].[Bed label]),descendants([Date].currentmember,[date].[day])), [Measures].[Utilisation Min]/ (24*60)) * 100'

感谢所有试图提供帮助的人!

答案 1 :(得分:0)

可能是因为空元组正在产生问题。使用CoalesceEmpty函数将用0替换EMPTY单元格。尝试以下代码:

CREATE MEMBER CURRENTCUBE.[Measures].UtilisationPercent
 AS avg( crossjoin(descendants([bedlabel].[hierarchy].currentmember, [Bedlabel].[Bedlabel]), 
descendants([Date].[date].currentmember, [Date].[Day])), CoalesceEmpty([Measures].[Utilisation Mins], 0) )
/ (24*60), 
FORMAT_STRING = "Percent", 
NON_EMPTY_BEHAVIOR = { [Utilisation Mins] }, 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Bedstay'  ;

由于AVG似乎无效,请检查以下脚本:

CREATE MEMBER CURRENTCUBE.[Measures].a
as 
SUM(
(descendants([bedlabel].[hierarchy].currentmember, [Bedlabel].[Bedlabel]) * descendants([Date].[date].currentmember, [Date].[Day])),
[Measures].[Utilisation Mins]),
NON_EMPTY_BEHAVIOR = { [Utilisation Mins] }, 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Bedstay'  ; 

CREATE MEMBER CURRENTCUBE.[Measures].b 
as
COUNT(
(descendants([bedlabel].[hierarchy].currentmember, [Bedlabel].[Bedlabel]) * descendants([Date].[date].currentmember, [Date].[Day]))
,EXCLUDEEMPTY
),
NON_EMPTY_BEHAVIOR = { [Utilisation Mins] }, 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Bedstay'  ; 

CREATE MEMBER CURRENTCUBE.[Measures].C
AS
[Measures].A/[Measures].B,
FORMAT_STRING = "Percent", 
NON_EMPTY_BEHAVIOR = { [Utilisation Mins] }, 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Bedstay'  ; 

答案 2 :(得分:0)

不是答案,但也许是一种深入了解正在发生的事情的方法。

请尝试添加以下指标:

CREATE MEMBER CURRENTCUBE.[Measures].UtilisationCount
 AS Count( 
    crossjoin(
      descendants([bedlabel].[hierarchy].currentmember, [Bedlabel].[Bedlabel])
     ,descendants([Date].[date].currentmember, [Date].[Day])
    )

然后在你的查询中添加这个新的度量,在列上,希望x,y,z,j,q将是一些数字 - 什么是q?:

January 2011    UtilisationCount   Utilisation %

Bed1            x                   98.86%
Bed2            y                   88.38%
Bed3            z                   82.63%
Bed4            j                   94.67%
Total           q                   894.35%