Question : Group sum calculated fields (which contain aggregate function) by group

I have been fighting with this one for days.

I have a report that pulls $$ per quarter for all projects, and it is grouped by project manager.  To get the $$ by quarter, I have a complex expression like:

"=(iif(Fields!Planned_x0020_Start_x0020_Date.Valueeters!SOCQ2.Value and Fields!Planned_x0020_End_x0020_Date.Value>Parameters!EOCQ2.Value,
datediff("d",Parameters!SOCQ2.Value,Parameters!EOCQ2.Value)+1,IIF(Fields!Planned_x0020_End_x0020_Date.Valuers!SOCQ2.Value,
0,datediff("d",Parameters!SOCQ2.Value,Fields!Planned_x0020_End_x0020_Date.Value))))*(Sum(Fields!jobs_job_x0020_Value.Value))/Fields!RemainingDays.Value"

This is working fine.

However, I need to take all the totals from  from this equation and sum it for each project manager ( the top level grouping).  becauseI have a nessted aggregate function, SSRS does not like this.  So I created the following code for the report:

Public Dim sumCQ2 As Double = 0

Public Function CalculateRowTotal(ThisValue As Double) As Double    
      sumCQ2= sumCQ2 + ThisValue    
      Return ThisValue
End Function

I have made the appropriate adjustments to the report and am having the following 2 issues:

1. At each grouping, it is doing a running total from teh previous group
2. The totals are appearing 1 group behind (fist group total is zero, second group total is the total for group 1, etc.)

Thanks for your assistance.

Answer : Group sum calculated fields (which contain aggregate function) by group

I resolved the issue.

There are 2 key things that have to occur to resolve:

1:  as many in the exchange have stated - you absolutely cannot have an aggregate function in the calculated fields that you want o aggregate again at the group level.  To get around this issue, I took the

"(Sum(Fields!jobs_job_x0020_Value.Value))"

in my original calculated field expression and had the SQL query string generate this same value  as "ProjectValue" as a field from the SQL query string.  So now the calculated contains the following at the end :

Fields!ProjectValue.Value/Fields!RemainingDays.Value

2. I used the runningValue function in the Group Footer, and it looks like this (Note-  the mess in the middle is the same formula I have in the detail line - I have bolded the elements of the runningvalue function):

=runningvalue((iif(Fields!Planned_x0020_Start_x0020_Date.Valuemeters!SOCQ2.Value and Fields!Planned_x0020_End_x0020_Date.Value>Parameters!EOCQ2.Value,
datediff("d",Parameters!SOCQ2.Value,Parameters!EOCQ2.Value)+1,IIF(Fields!Planned_x0020_End_x0020_Date.Valueeters!SOCQ2.Value,
0,datediff("d",Parameters!SOCQ2.Value,Fields!Planned_x0020_End_x0020_Date.Value))))* Fields!ProjectValue.Value/Fields!RemainingDays.Value, sum, "table1_ProjectManager")


table1_ProjectManger is the name of the group section.

After 1.5 weeks of banging my head against the wall - I finally had a solution that worked!
Random Solutions  
 
programming4us programming4us