【问题标题】:cognos report studio multiple columns averagecognos Report Studio 多列平均值
【发布时间】:2016-01-20 08:40:47
【问题描述】:

我对 cognos 比较陌生,所以请记住这一点。

我想在 Report Studio 中创建一个报告,其中我有 3 个度量(ABC)作为列和第 3 个计算列作为这些列的平均值。

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

我尝试了算术替代方法 (a+b+c)/3,因为这不会处理值为空的情况

提前谢谢你

【问题讨论】:

  • 您可以计算 a b c 并在 null 然后 0 时放置大小写

标签: business-intelligence cognos


【解决方案1】:

如果 null 的平均值不为零

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

【讨论】:

  • 感谢您的建议。但是,在这种情况下,平均值不会是 (/3),它需要除以非空元素的数量
  • 我认为这是解决问题的一种方法。我得出了类似的解决方案。如果这不是问题的答案,则需要对问题进行编辑以使其清晰。
【解决方案2】:

我会创建一个值计数表达式来计算非空列:

值计数

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 有问题,可以将平均值表达式包裹在另一个 CASE 中,以在 [Value Count] 为 0 时返回 null:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多