Link to home
Start Free TrialLog in
Avatar of tgraffham
tgraffhamFlag for United States of America

asked on

Access Report: Compute percentage of total for each line

How can I do this on an Access Report:

Header:    Field               Value        Percent
               ----------------------------------------
Detail       Item 1              10           25%
Section:   Item 2              10           25%
               Item 3              20           50%
               ----------------------------------------
Footer:    Total:               40          100%

I haven't played much with using code behind the report to process data line by line but I'm assuming that would be one way.  Any quick pointers or code snippets to get me started quickly would be appreciated.

Thanks,
Tim
ASKER CERTIFIED SOLUTION
Avatar of alexgud
alexgud
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, Can't do =Sum([Percent]) but other then this should work
Avatar of ahmedbahgat
ahmedbahgat

you can create a function to return the percent for each record, and we will pass each record field value as the argument:

in a global module, we create the function:

Function MyPercent(MyValue)
  MyPercent = 100 * MyValue/DSum("[FieldValue]", "MyTable")
End Function

now in the report query create a new column, that will look like this:

ValuePercent: MyPercent([FieldValue])

finaly bound the textbox for the percent to the new column we created


cheers
are you talking about Access reort from access database ?????
I" am assuming that this  is Detail report only.

Create query as Test1

SELECT test.field, Sum(test.value) AS SumOfvalue
FROM test
GROUP BY test.field;

Create query for your reports

SELECT test.field, test.value, test1.SumOfvalue
FROM test1 INNER JOIN test ON test1.field = test.field;

Add field and value to your detail part in reports
Add field in Report footer as total with control source as =Sum([value])
Now add new text fields having control source as =Sum([Value])/([Total])
And In Report footer copy the same.

I hope this will help.

Regards
Sparab
=[Value]*100/Sum([Value]) & "%"

If you want to calculate sum and percentage of Value of each group.
Avatar of tgraffham

ASKER

Thanks for the help.  I don't think my head was on straight considering how simple the solution was.  I had it in my brain that I wouldn't get the correct results if I did aggregate functions at the detail level.  Needless to say, it works fine.

The only thing I had to keep track of was the difference between totals and subtotals.  To divide and get the percent in my group by subtotals, I could just divide my subtotal of [Value] by Sum([Value]) as it would always equal 100%.  Instead I had to make sure to divide the controls rather than the fields: txtSubTotalValue / txtGrandTotalValue.  This works great.

Thanks again,
Tim