Solved

Access Report: Compute percentage of total for each line

Posted on 2004-04-20
6
537 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:tgraffham
6 Comments
 
LVL 4

Accepted Solution

by:
alexgud earned 125 total points
ID: 10873303
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
 
LVL 4

Expert Comment

by:alexgud
ID: 10873490
Sorry, Can't do =Sum([Percent]) but other then this should work
0
 
LVL 16

Expert Comment

by:ahmedbahgat
ID: 10873882
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 11

Expert Comment

by:sparab
ID: 10875361
are you talking about Access reort from access database ?????
0
 
LVL 11

Expert Comment

by:sparab
ID: 10875436
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.
0
 
LVL 1

Author Comment

by:tgraffham
ID: 10879534
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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question