PC Review


Reply
Thread Tools Rate Thread

Calculate Percentage of Total for Category

 
 
LC
Guest
Posts: n/a
 
      6th Apr 2011
Hi

I'm trying to calculate Percentage of Totals for certain categories
For example:

Table: Sales
===================
Product Region Amount
Apple North 50
Apple South 40
Pear North 30
Orange East 20
Orange West 60
Orange South 20

I know I can create a query to group information as follows

Query: Group
==========
Product Amount
Apple 90
Pear 30
Orange 100

How Do I move back this info to the Sales Table to build the following
result:

Table: Sales (New)
===================
Product Region Amount Total PercetOfCat
Apple North 50 90 =50/90
Apple South 40 90 =40/90
Pear North 30 30 =30/30
Orange East 20 100 =20/100
Orange West 60 100 =60/100
Orange South 20 100 =20/100

Thanks in advance,
LC


 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      6th Apr 2011
Save your totals query and join it back to the table

SELECT Product, Region, Amount
, QueryTotals.TotalAmount
, Amount/QueryTotals.TotalAmount as PerCentOfCat
FROM Sales INNER JOIN QueryTotals
ON Sales.Product = QueryTotals.Product

In query design view
== Add the table to the query
== Add the totals query to the query
== Join the product fields together (drag from one to the other)
== Select the fields you want to display
== Make the calculated total (percent) by entering
[Amount]/[QueryName].[TotalAmount]
into a field rectangle

Use this query as if it were a table. Do not make a new table.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 4/6/2011 3:24 AM, LC wrote:
> Hi
>
> I'm trying to calculate Percentage of Totals for certain categories
> For example:
>
> Table: Sales
> ===================
> Product Region Amount
> Apple North 50
> Apple South 40
> Pear North 30
> Orange East 20
> Orange West 60
> Orange South 20
>
> I know I can create a query to group information as follows
>
> Query: Group
> ==========
> Product Amount
> Apple 90
> Pear 30
> Orange 100
>
> How Do I move back this info to the Sales Table to build the following
> result:
>
> Table: Sales (New)
> ===================
> Product Region Amount Total PercetOfCat
> Apple North 50 90 =50/90
> Apple South 40 90 =40/90
> Pear North 30 30 =30/30
> Orange East 20 100 =20/100
> Orange West 60 100 =60/100
> Orange South 20 100 =20/100
>
> Thanks in advance,
> LC
>
>

 
Reply With Quote
 
LC
Guest
Posts: n/a
 
      7th Apr 2011
Works...Thanks John
At first I was pointing into that direction, but there were mistakes
in my Group Query and result was very strange. After correcting the
group query, it looks Ok.
 
Reply With Quote
 
LC
Guest
Posts: n/a
 
      13th Apr 2011
Hi,

The solution above works great for generating the query:

SELECT Product, Region, Amount
, QueryTotals.TotalAmount
, Amount/QueryTotals.TotalAmount as PerCentOfCat
FROM Sales INNER JOIN QueryTotals
ON Sales.Product = QueryTotals.Product

QueryTotals
===================
Product Region Amount TotalAmount PercetOfCat
Apple North 50 90 =50/90
Apple South 40 90 =40/90
Pear North 30 30 =30/30
Orange East 20 100 =20/100
Orange West 60 100 =60/100
Orange South 20 100 =20/100

How can I transfer those results to the table Sales
-After creating the fields Total and PercentOfCat

Table: Sales
===================
Product Region Amount Total PercentOfCat
Apple North 50
Apple South 40
Pear North 30
Orange East 20
Orange West 60
Orange South 20

Regards
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      13th Apr 2011
On Wed, 13 Apr 2011 13:12:23 -0700 (PDT), LC <(E-Mail Removed)> wrote:

>Hi,
>
>The solution above works great for generating the query:
>
>SELECT Product, Region, Amount
>, QueryTotals.TotalAmount
>, Amount/QueryTotals.TotalAmount as PerCentOfCat
>FROM Sales INNER JOIN QueryTotals
>ON Sales.Product = QueryTotals.Product
>
>QueryTotals
>===================
>Product Region Amount TotalAmount PercetOfCat
>Apple North 50 90 =50/90
>Apple South 40 90 =40/90
>Pear North 30 30 =30/30
>Orange East 20 100 =20/100
>Orange West 60 100 =60/100
>Orange South 20 100 =20/100
>
>How can I transfer those results to the table Sales
>-After creating the fields Total and PercentOfCat


Why would you want to?

Storing data which can be calculated from data already in the table wastes
disk, wastes time (almost any calculation will be very fast), and worst, risks
storing invalid data. Adding a single record will throw all your percentages
off. Just store the actual amount, and use a Query when you need to calculate
the totals and percents.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
LC
Guest
Posts: n/a
 
      13th Apr 2011
Hi

I'm working on a project where the final output is an Income Statement
(Excel Pivot Table).
The reason for copying information from a Query into a Table is
because there are sequential calculations: one must end before the
other begins.

Creating the entire Income Statement nesting several Queries is
possible but there are problems with memory.

That's why we're trying to copy information into a table as soon as
calculations are completed.

Regards.
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      13th Apr 2011
On Wed, 13 Apr 2011 14:36:09 -0700 (PDT), LC <(E-Mail Removed)> wrote:

>Hi
>
>I'm working on a project where the final output is an Income Statement
>(Excel Pivot Table).
>The reason for copying information from a Query into a Table is
>because there are sequential calculations: one must end before the
>other begins.
>
>Creating the entire Income Statement nesting several Queries is
>possible but there are problems with memory.
>
>That's why we're trying to copy information into a table as soon as
>calculations are completed.
>
>Regards.


In that case, you should be able to base an Append query on this calculated
query.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate days less than X as percentage of total turn around time Joe Microsoft Access Queries 3 5th Dec 2008 06:42 PM
How does one calculate a percentage on the total in a query? =?Utf-8?B?Um9zZQ==?= Microsoft Access Queries 3 18th Oct 2007 06:23 PM
Calculate percentage completed from total attendees =?Utf-8?B?c2x5Y2tl?= Microsoft Access 2 30th Nov 2005 08:00 PM
How to calculate percentage in my total query? awu Microsoft Access Queries 1 11th Oct 2005 06:10 AM
Calculate percentage and total multiple results =?Utf-8?B?VGFtbXkgUw==?= Microsoft Access 3 9th Jun 2005 03:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:38 PM.