Skip to Content
0
Former Member
Jan 12, 2011 at 07:30 AM

Calculate average in alv grid without blank rows

67 Views

Hi all,

I am having a requirement to calculate averages(for column C) as shown in below example.

This is done as alv grid report

Example output:

Col A Col B Col C (%)

200 40 20

250 75 30

Subtotal 450 115

300 150 50

400 80 20

150 0

40 0

Subtotal 850 270

Grand total 1300 385

Here col C is calculated as below:

if col A is not initial and col B is not initial.

col C = ( col B / col A ) * 100

Subtotals and grand totals for Col A and Col B are calculated using standard functions like passing subtot = X in it_sort and do_sum = X in it_feildcat.

I tried calculating averages for col C by passing do_sum = C in it_fieldcat but it is considering blank rows to calculate average which should not happen. In our example for col C grand total should display as (120/4) 30 but it is displaying as (120/6) 20 which is wrong.

Func owner said it will be fine if we can calculate the grand total for col C as like above formula ( 385 / 1300 ) * 100 which is 29.61. But how to get the grand totals of other columns into the program when they are calculated using standard functionality and even if we do this in program how to pass this average tot of col C to alv grid display func module.

Kindly suggest.

Regards

Srinivas B