Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (i.e. 1.0), not the ratio of the values to the left of it. I've tried calculating the sum as:

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

but that gives the 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).

I copied the value from the runningValue textbox in the ratio column in the total row.

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.

like image 877
Garius Avatar asked Apr 20 '11 13:04

Garius


2 Answers

Try Sum((Fields!one.Value / Fields!two.Value)).

like image 180
Ann L. Avatar answered Sep 20 '22 18:09

Ann L.


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.

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.

Then ratio will be a selection you can add to your table as an actual field instead of an expression. You can then total it.

like image 24
Amanda Matthews Avatar answered Sep 21 '22 18:09

Amanda Matthews