Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Reporting Services Development
 Urgent : Sum of calculated column

Author  Topic 

Beginer2012
Starting Member

45 Posts

Posted - 2012-05-16 : 09:32:26
Hello,
My dataset contains two column and ID column and a NumberOfCases columns.
I'm calculating the percentage of each ID in the table by dividing each NumberOfcases by total numberOfCases. How ever I want to give a sum of these percentages in the Last row. How can I sum an expression in the table ?

Thank you

Example:
ID NumberOfCases Percentage
1 17 10.0 %
2 28 16.5 %
3 30 17.6 %
4 45 26.5 %
6 50 29.4 %

Total 170 100 % ==========> I need this % total.

The total of NumberOfCases is easy to get by having a sum on a field...But the percentage is not a field...It is calculated in an expresion in the table.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-16 : 20:32:50
you can add a similar expression for totalrow to make it calculate over the dataset.use scope as dataset name when applying the required aggregate functions.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Beginer2012
Starting Member

45 Posts

Posted - 2012-05-17 : 17:35:21
Can you elaborate more please??
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-17 : 18:14:33
Well, the sum will always be 100%, so why would you want to sum it?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

vasu_thiagu
Starting Member

1 Post

Posted - 2012-05-25 : 06:04:50
Use this:

select id, NoCases, NoCases*100/(select sum(NoCases) from Cases) from Cases
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-25 : 10:40:29
quote:
Originally posted by Beginer2012

Can you elaborate more please??



you can put expression like

=SUM(Fields!yourfield.value,"your required scope here")


for percentage you can yuse like

SUM(Fields!NumberOfcases.value)/SUM(Fields!NumberOfcases.value,"datasetname")

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -