Average of a Group

Recommended Posts

By: Brett - bsutton

Average of a Group

2004-11-24 17:25

I'm trying to calculate the average of a group.

I have create a variable for the group which correctly sums the details of the group.

<variable name="SUM_FOR_DAY" class="java.lang.Integer" resetType="Group" resetGroup="Date" calculation="Sum">

<variableExpression><![CDATA[\$F{Count}]]></variableExpression>

</variable>

I then created a variable which is intended to print an average of the group at the end of the report.

<variable name="AVERAGE_FOR_PERIOD" class="java.lang.Integer" resetType="Report" calculation="Average">

<variableExpression><![CDATA[\$V{SUM_FOR_DAY}]]></variableExpression>

</variable>

However the value printed is clearly not the average.

Can any one suggest where I'm going wrong?

By: Teodor Danciu - teodord

RE: Average of a Group

2004-11-25 00:44

Hi,

You average variable should look like this:

<variable name="AVERAGE_FOR_PERIOD" class="java.lang.Integer" resetType="Report"

calculation="Average"> <variableExpression><![CDATA[\$F{Count}]]></variableExpression>

</variable>

I hope this helps.

Teodor

By: Brett - bsutton

RE: Average of a Group

2004-11-29 19:41

Thanks for the reply but thats not quite what I'm looking for and I probably didn't explain it very well.

What I'm trying to do is determine the average of the groups not the individual line items.

As an example

if D: represents a detail line with a value

and G: represents a group line with a value which is the sum of the associated detail lines.

D: 4

D: 1

G: 5

D: 1

D: 3

D: 1

G: 4

The the average should be 4.5 as calculated by:

4.5 = (5 + 4) / 2 where 5 and 4 are the group totals.

Average = 1.8 which is 9 / 5

i.e 9 is the total of all detail lines and 5 is the no. of detail lines.

• Replies 0
• Created