Solved

Access Report: Compute percentage of total for each line

Posted on 2004-04-20
6
523 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now