2016-01-20 56 views
0

我对cognos比较陌生,所以请记住这一点。cognos报告工作室多栏平均

我想创造在报告工作室的报告,其中i有3项措施(Ç)为列和第三列计算作为平均这些列。

但是,当使用平均函数时,我无法添加多个输入。

我试图算术替代(A + B + C)/ 3,因为这将无法处理的情况下,当值均为空

预先感谢您

+0

您可以计算abc并在nul然后0 – sagi

回答

0

如果空值不为零的平均

case when 
    not (a is null and b is null and c is null) 
then 
    (coalesce(a,0) + coalesce(b,0) + coalesce(c,0))/
    (case when a is not null then 1 else 0 end + 
    case when b is not null then 1 else 0 end + 
    case when c is not null then 1 else 0 end) 
end 
+0

感谢您的建议。然而,在这种情况下,平均值不会是(/ 3)它将需要在非空元素的数量上划分 – CognosNewbie

+0

我认为这是解决问题的一种方法。我来到了一个类似的解决方案。如果这不是问题的答案,那么需要对问题进行编辑以确保清晰。 – Johnsonium

0

我会创造一个价值数表达式计数非空列:

价值COUN牛逼

CASE WHEN [A] is not null THEN 1 ELSE 0 
+ 
CASE WHEN [B] is not null THEN 1 ELSE 0 
+ 
CASE WHEN [C] is not null THEN 1 ELSE 0 

然后你就可以使用这个新的数据项作为股息为您平均值计算:

平均

(coalesce([A],0) + coalesce([B],0) + coalesce([C],0))/[Value Count] 

如果除以0是一个问题,你可以用普通的表达在[Value Count]为0时返回null的另一个CASE中:

CASE 
WHEN [Value Count] > 0 THEN (coalesce([A],0) + coalesce([B],0) + coalesce([C],0))/[Value Count] 
ELSE null 
END