简体   繁体   English

在 SSRS 中对一列表达式求和

[英]Summing a column of expressions in SSRS

The detail row in my table contains a column with an expression:我的表中的详细信息行包含一个带有表达式的列:

=sum(Fields!one.Value) / sum(Fields!two.Value)

I want to sum that column, but the results I get are not the sum of the ratios, but the ratio of the sums.我想对该列求和,但我得到的结果不是比率的总和,而是总和的比率。

For example:例如:

sum(Fields!one.Value)  sum(Fields!two.Value)    ratio
              3                      6                0.5 
              3                      6                0.5 
total:        6                     12                0.5

I want the bottom right corner value to be the sum of the values above it (ie 1.0 ), not the ratio of the values to the left of it.我希望右下角的值是它上面的值总和(即1.0 ),而不是它左边的值的比率。 I've tried calculating the sum as:我试过将总和计算为:

sum( sum(Fields!one.Value) / sum(Fields!two.Value) )

but that gives the 0.5 .但这给出了0.5

Anyone have any ideas?谁有想法?


My Solution:我的解决方案:

I added another column to the right of the ratio column and set its visibility to "not visible".我在比率列的右侧添加了另一列,并将其可见性设置为“不可见”。 In the detail row, I added this expression:在详细信息行中,我添加了以下表达式:

=runningValue( sum(Fields!one.Value) / sum(Fields!two.Value), Sum, "table1_grp")

( table1_grp is in internal group). table1_grp在内部组中)。

I copied the value from the runningValue textbox in the ratio column in the total row.我从总计行中比率列的runningValue文本框中复制了值。

The expression is:表达式为:

=ReportItems!Textbox55.Value  

So, the running sum is invisible in the table, but I use the final value in the total row.所以,运行总和在表中是不可见的,但我在总行中使用了最终值。


UPDATE:更新:

My colleague came up with an elegant solution.我的同事想出了一个优雅的解决方案。

In ratio total box, use the following expression:在比率总计框中,使用以下表达式:

=sum( sum(Fields!one.Value, "table1_grp") / sum(Fields!two.Value, "table1_grp") )  

adding the scope to the inner sums does the trick.将范围添加到内部总和可以解决问题。

You could add a calculated field in your data set that creates the ratio.您可以在数据集中添加一个计算字段来创建比率。

I - Insert the data field instead of the expression directly in the field. I - 直接在字段中插入数据字段而不是表达式。

Now you have it total by right-clicking and selecting add a total.现在您可以通过右键单击并选择添加总计来获得总计。

II - Right-click on your data set, select Add calculated field, name it ratio, add your expression here. II - 右键单击​​您的数据集,选择添加计算字段,将其命名为比率,在此处添加您的表达式。

Then ratio will be a selection you can add to your table as an actual field instead of an expression.然后 ratio 将是一个选择,您可以将其作为实际字段而不是表达式添加到表中。 You can then total it.然后你可以总计它。

试试 Sum((Fields!one.Value / Fields!two.Value))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM