1

我正在使用 SSRS 矩阵控制开发报告。

这是我正在使用的示例表

混音

这就是我在 SSRS 中使用矩阵工具尝试实现的目标

结果

好的现在描述

报告需要按位置代码对类型 A、B、C 及其案例数量进行分组。第 6 行将包含从第 4 行和第 5 行(类型 A 和类型 B)派生的计算值。

如屏幕截图所示,用于得出结果的公式(44 美元)是通过使用公式

(Case Value of Type B * average of Type B) + (Case Value of Type C * average of Type C)
-------------------------------------------------------------------------------------
                           (Case Value of Type B + Case Value of Type C)

所以 44 美元的价值可以实现为

(57 * 18) + (44 * 78) / (57 + 44)

有人可以指导我如何在 ssrs 中实现这一点。我已经制作了结构,但无法计算总值。

4

1 回答 1

1

这取决于您如何获得平均值。这是在幕后发生的,是您预先确定的,还是根据您可以加入的其他表进行的?

如果它全部在您可以获得的数据集中,我会这样做:

  1. 确定一个既是您的数据又是您的平均值的数据集。我不确定您是来自 SQL 还是只是在 Excel 中完成这一切。我将暂时在 SQL 中进行模拟:

    declare @Avgs Table ( location int, type varchar(1), cs int, average int);
    
    insert into @Avgs values (1, 'A', 21, 10),(1, 'B', 57, 18),(1, 'C', 44, 78);
    
    Select top 10 *
    from @Avgs
    
  2. 您可能想添加一个“计算列”或直接在 SQL 中进行数学运算,因为 SSRS 中的表达式编辑器对于一两个函数通常是可以的,但是当您非常参与数学运算时,我发现 SQL 引擎更适合处理它. 这也使得以后改变事情变得更好。

  3. 所以我会这样修改SQL:

    declare @Avgs Table ( location int, type varchar(1), cs int, average int);
    
    insert into @Avgs values (1, 'A', 21, 10),(1, 'B', 57, 18),(1, 'C', 44, 78);
    
    With a as 
         (
         select *, cs * average as compound
         from @Avgs
         )
     , b as 
         (
         Select 
             (max( case when type = 'B' then compound end) +    max( case when type = 'C' then compound end)) /
             (max( case when type = 'B' then cs end) + max( case when type = 'C' then cs end))  as CompoundMath
         from a
        )
    select *
    from a, b
    
  4. 这将是您在 SSRS 中的数据集,复合函数可以在(case when ... end)内部更改,在“when”是逻辑之后,在“then”之后是什么结果。

  5. 只需添加一个新行,您就可以将自定义表达式设置为名为“复合数学”的列。

于 2013-03-29T18:00:12.823 回答