• Status: Solved
• Priority: Medium
• Security: Public
• Views: 582

# Access Report: Compute percentage of total for each line

How can I do this on an Access Report:

----------------------------------------
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
0
tgraffham
1 Solution

Commented:
Why don't you put =100*[Value]/Sum([Value]) in the report field for Percent
and for footer just =Sum([Value]) for value and =Sum([Percent]) for percent
0

Commented:
Sorry, Can't do =Sum([Percent]) but other then this should work
0

Commented:
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
0

Commented:
are you talking about Access reort from access database ?????
0

Commented:
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;

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

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.
0

Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.