473,659 Members | 3,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find percentages in Access query

107 New Member
Hello,
can I write a query that will give percentages of records in one field?
table example:
Expand|Select|Wrap|Line Numbers
  1. table1
  2. IdNumber    model    condition
  3. 01              045         good
  4. 01              045         bad
  5. 02              046         new
  6. 03              047         damaged
  7. 02              046         new
  8. 02              046         old
  9. 03              047         new
  10. 03              047         new
  11. 01              045         damaged
I have 4 things the field conditon can be good, bad, new, and damaged.
Is there any way to show them in percent values?
thank you
Jan 22 '09 #1
7 6083
DonRayner
489 Recognized Expert Contributor
Based on your table data above you could do it like this

Expand|Select|Wrap|Line Numbers
  1. SELECT ((Sum(IIf([Table1]![condition]="new",1,0)))*100)/Sum(IIf([Table1]![condition] Like "*",1,0)) AS NewCount, ((Sum(IIf([Table1]![condition]="old",1,0)))*100)/Sum(IIf([Table1]![condition] Like "*",1,0)) AS OldCount, ((Sum(IIf([Table1]![condition]="good",1,0)))*100)/Sum(IIf([Table1]![condition] Like "*",1,0)) AS GoodCount, ((Sum(IIf([Table1]![condition]="bad",1,0)))*100)/Sum(IIf([Table1]![condition] Like "*",1,0)) AS BadCount, ((Sum(IIf([Table1]![condition]="damaged",1,0)))*100)/Sum(IIf([Table1]![condition] Like "*",1,0)) AS DamagedCount
  2. FROM Table1;
  3.  
Just change all the "Table1" to whatever you table name is
Jan 22 '09 #2
buddyr
107 New Member
thank you- that works
Jan 23 '09 #3
ADezii
8,834 Recognized Expert Expert
@buddyr
Another Option (change to your Table Name)
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT ServiceRec.Condition, Format(DCount("*","ServiceRec","[Condition] = '" & 
  2. [Condition] & "'")/DCount("*","ServiceRec"),"Percent") AS [Percent]
  3. FROM ServiceRec
  4. ORDER BY ServiceRec.Condition;
Expand|Select|Wrap|Line Numbers
  1.  
  2. Condition            Percent
  3. bad                   10.00%
  4. damaged               20.00%
  5. good                  10.00%
  6. new                   40.00%
  7. old                   20.00%
  8.  
Jan 23 '09 #4
buddyr
107 New Member
now your making it look easy- thank you
Jan 23 '09 #5
NeoPa
32,568 Recognized Expert Moderator MVP
To reduce the number of function calls, I've started with ADezii's SQL and doctored it a little. I've also allowed the formatting to be controlled by whatever is using the query. Format() returns a string which may not always suit your requirements.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Condition],
  2.        Count(*)/DCount('*','[ServiceRec]') AS [Percent]
  3.  
  4. FROM [ServiceRec]
  5.  
  6. GROUP BY [Condition]
  7.  
  8. ORDER BY [Condition]
Jan 23 '09 #6
ADezii
8,834 Recognized Expert Expert
@NeoPa
Nah, not as pretty! (LOL)!
Expand|Select|Wrap|Line Numbers
  1.  
  2. Condition            Percent 
  3. bad                   0.1 
  4. damaged               0.2 
  5. good                  0.1 
  6. new                   0.4 
  7. old                   0.2 
  8.  
Jan 24 '09 #7
NeoPa
32,568 Recognized Expert Moderator MVP
That's cos you missed a bit A - XD.
The formatting is done in whatever uses the SQL (QueryDef, Report, etc).
That way it shows how you want it when displayed, and is also usable as a value in the code ;)
Expand|Select|Wrap|Line Numbers
  1. Condition            Percent 
  2. Bad                   10%
  3. Damaged               20%
  4. Good                  10%
  5. New                   40%
  6. Old                   20%
Jan 24 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1170
by: Avinash Dhoot | last post by:
Hi, I have a 5 row table with the following values. key value 1 5 2 10 3 15 4 15 5 5
2
14915
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data in the format that I need it in order to create the reports that we use. So far this has proven to be successful for the reports that I am doing and the data that I am pulling into it. I just have one challenge that may require a lot of work and I...
26
2238
by: Mike Barnard | last post by:
Hi all. I am playing with html and css. I don't (yet) have a working site, I'm just trying to build a working, basic template I can use for a couple of ideas I have. I recall reading a discussion in a newsgroup in the past that came to the conclusion that the best way to use font sizes with css was to use percentages. Is that still the case? If so, how does one implement it?
1
1688
by: Bob Alston | last post by:
I need to produce a report like this Color: # % ------ --- --- White 10 20 Black 25 50 other 15 30 ---- ---- Total 50 100
9
27827
by: AZKing | last post by:
Hi all, I would like to know how do you go about calculating percentages in Access. For example, in a form I have 3 combo boxes with drop down menus where a user can select "Yes" or "No" and a text box where I will calculate a percentage. What I am looking for is something like this: If combo1 = "yes" then percentagebox = 1 / 3 * 100 ElseIf combo1 AND combo2 = "Yes" then percentagebox = 2 / 3 * 100 ElseIf combo1 AND combo2 AND combo3...
3
7125
by: HBH | last post by:
I am using Access 2003. I made a pie chart from a query for the sum in each catagory i am using. I want the chart to show the sum and also the percentage of the total.
5
2986
by: eliana82 | last post by:
I have problems calculating score percentages within groups. I have created a boat program in access where the information provided is name, team, boat and score. The first query I've done is to produce the ranking according to the score, which worked fine. The second query is about giving 100% to the highest score per boat and then taking the percentage of that score and calculate the rest of the team scores according to that score;...
1
4279
by: marcnz | last post by:
I have been charged of creating a coldfusion web site for our company. Our database has a ms sql 2005 backend and ms access frontend. Almost all tables are linked tables with the SQL database, except the temp tables needed at runtime that are in the ms access database. It will be easier for us to utilize the ms access queries and temp tables, so I set up a datasource on our web server and within the coldfusion administrator to point to the ms...
3
2071
by: martin DH | last post by:
Access 2003 I have a table (TASKS) filled with data from an external source. The table lists several tasks for employees to complete and has a text field (STATUS) that identifies where in the completion process the task is by a single alpha character (e.g. C=Complete, N=Not Started, A=Actively Working, W=Waiting, and X=Not Applicable). I have reports that query the table and provide reports specific to a task or to who is responsible for...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.