Calculating a weighted average for a group
I have a reports similar to the following:
I need it to look like the following:
The report is 开发者_如何学编程grouped by Department. I cannot figure out how to create the formula field YTD AVG to calculate and show in each group footing and then reset for the next group.
I understand the calculation for the YTD AVG, for example YTD AVG for dept1 would be:
((80*100)+(100*40)) / (100+40)
I just don't know how to get it in Crystal Reports.
Use Crystal's weighted average summary function:
- Insert a summary, and select the group footer
- Select the database field containing the average
- Select Weighted average with
- Select the field containing the number of responses
Create a formula called 'Month_Total' and place it in the details section for each row/month and suppress it {month.average} * {month.responses}
In your example, this will give you the "(80*100)" and "(100*40)" portions.
Create another formula called 'Department_Avg' and place it in the department group footer section sum({@Month_Total},{month.month_name}) / sum({month.responses},{month.month_name})
The second parameter to Sum() should match whatever department-related field you're already grouping on and specifies that you want to sum only over the individual groups. This will give you your entire YTD calculation for each group/department.
精彩评论