Hello,
can I write a query that will give percentages of records in one field?
table example: -
table1
-
IdNumber model condition
-
01 045 good
-
01 045 bad
-
02 046 new
-
03 047 damaged
-
02 046 new
-
02 046 old
-
03 047 new
-
03 047 new
-
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
7 6083
Based on your table data above you could do it like this -
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
-
FROM Table1;
-
Just change all the "Table1" to whatever you table name is
ADezii 8,834
Recognized Expert Expert @buddyr
Another Option (change to your Table Name) - SELECT DISTINCT ServiceRec.Condition, Format(DCount("*","ServiceRec","[Condition] = '" &
-
[Condition] & "'")/DCount("*","ServiceRec"),"Percent") AS [Percent]
-
FROM ServiceRec
-
ORDER BY ServiceRec.Condition;
-
-
Condition Percent
-
bad 10.00%
-
damaged 20.00%
-
good 10.00%
-
new 40.00%
-
old 20.00%
-
now your making it look easy- thank you
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. - SELECT [Condition],
-
Count(*)/DCount('*','[ServiceRec]') AS [Percent]
-
-
FROM [ServiceRec]
-
-
GROUP BY [Condition]
-
-
ORDER BY [Condition]
ADezii 8,834
Recognized Expert Expert @NeoPa Nah, not as pretty! (LOL)! -
-
Condition Percent
-
bad 0.1
-
damaged 0.2
-
good 0.1
-
new 0.4
-
old 0.2
-
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 ;) - Condition Percent
-
Bad 10%
-
Damaged 20%
-
Good 10%
-
New 40%
-
Old 20%
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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?
|
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
|
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...
| |
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.
|
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;...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |