473,508 Members | 4,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count and percentage of specific records

58 New Member
This is an example of what I have so far in my Access Report.

Internet Source Salesperson... …Appointment Kept
AutoTrader … yes
AutoTrader … No
AutoTrader … No
AutoUSA … Yes
AutoUSA … Yes
Ebay … No
mbUSA.com … yes
Others … No
Others … No
Code =Count(*) =Count(IIf([Appointment Kept]="Yes",0))
Count 9 4

The Idea is the following:
How can I count how many [Appointment Kept]=“Yes” (1 ) Only for [Internet Source]=”AutoTrader”,(3) in order to get a percentage between them (1/3). In other words, the percentage of all “yes” of only AutoTrader
Thank you for any assistance

plaguna
Oct 1 '08 #1
23 3898
ADezii
8,834 Recognized Expert Expert
Assuming your Table Name is tblAuto, and the [Appointment Kept] Field is a Yes/No Field, Copy and Paste the following Expression into the Control Source Property of a Text Box on your Report, preferably in the Report Footer:
Expand|Select|Wrap|Line Numbers
  1. =Format$(DCount("*","tblAuto","[Appointment Kept] = True And [Internet Source Salesperson] = 'AutoTrader'")/DCount("*","tblAuto","[Appointment Kept] = True"),"Percent")
P.S. - Substitute your Table Name for tblAuto.
Oct 1 '08 #2
plaguna
58 New Member
The code you gave me gives me an #error output

=Format$(DCount("*","BDC Information","[Appointment Kept] = 'YES' And [Internet Source] = 'AutoTrader'")/DCount("*","BDC Information","[Appointment Kept] = 'YES'"),"Percent")

The table that I sent before didn't show clearly. This is a good one:

[Internet Source]......…[Appointment Kept]
AutoTrader.…………………YES
AutoTrader.…………………YES
AutoTrader.…………………NO
AutoUSA.…………………..YES
AutoUSA.…………………..YES
Ebay…………………….…..NO
mbUSA.com.………………YEs

Code for Count:
=Count(IIf([Appointment Kept]="YES",0))
Total Yes = 5

=Count(IIf([Internet Source]="AutoTrader",0))
Total AutoTrader = 3

I have no problem so far.

Now, how can I count the [Appointment Kept] “Yes” of “AutoTrader”. I want to count the two “Yes” out of the three “AutoTrader” (once I figure this out first, I can get the percentage later)

I tried this code, and the ouput is -1 if there is any “YES” in the field, and an output of 0 if all are “NOs”
Code:
=Count(IIf([Appointment Kept]="YES",0)) And Count(IIf([Internet Source]="AutoTrader",0))

Also I tried part of your code and It didn’t work
Code:
=Format$(DCount("*","BDC Information","[Appointment Kept] = 'YES' And [Internet Source] = 'AutoTrader'"))

Any help will be greatly appriciated

plaguna
Oct 2 '08 #3
ADezii
8,834 Recognized Expert Expert
The code you gave me gives me an #error output

=Format$(DCount("*","BDC Information","[Appointment Kept] = 'YES' And [Internet Source] = 'AutoTrader'")/DCount("*","BDC Information","[Appointment Kept] = 'YES'"),"Percent")

The table that I sent before didn't show clearly. This is a good one:

[Internet Source]......…[Appointment Kept]
AutoTrader.…………………YES
AutoTrader.…………………YES
AutoTrader.…………………NO
AutoUSA.…………………..YES
AutoUSA.…………………..YES
Ebay…………………….…..NO
mbUSA.com.………………YEs

Code for Count:
=Count(IIf([Appointment Kept]="YES",0))
Total Yes = 5

=Count(IIf([Internet Source]="AutoTrader",0))
Total AutoTrader = 3

I have no problem so far.

Now, how can I count the [Appointment Kept] “Yes” of “AutoTrader”. I want to count the two “Yes” out of the three “AutoTrader” (once I figure this out first, I can get the percentage later)

I tried this code, and the ouput is -1 if there is any “YES” in the field, and an output of 0 if all are “NOs”
Code:
=Count(IIf([Appointment Kept]="YES",0)) And Count(IIf([Internet Source]="AutoTrader",0))

Also I tried part of your code and It didn’t work
Code:
=Format$(DCount("*","BDC Information","[Appointment Kept] = 'YES' And [Internet Source] = 'AutoTrader'"))

Any help will be greatly appriciated

plaguna
The code you gave me gives me an #error output

=Format$(DCount("*","BDC Information","[Appointment Kept] = 'YES' And [Internet Source] = 'AutoTrader'")/DCount("*","BDC Information","[Appointment Kept] = 'YES'"),"Percent")
That is not the code I gave you. The code I gave you, plus the revision on the Table Name because of the Space, is:
Expand|Select|Wrap|Line Numbers
  1. =Format$(DCount("*", "[BDC Information]", "[Appointment Kept] = True And [Internet Source Salesperson] = 'AutoTrader'") / DCount("*", "[BDC Information]", "[Appointment Kept] = True"), "Percent")
P.S. - This Expression goes into the Control Source of a Text Box. The [Appointment Kept] Field is a Yes/No Field.
Oct 2 '08 #4
plaguna
58 New Member
Your expression makes sense but for some reason It doesn’t work. I’m still having an #error output. Is there another way to do it?
Oct 3 '08 #5
ADezii
8,834 Recognized Expert Expert
Your expression makes sense but for some reason It doesn’t work. I’m still having an #error output. Is there another way to do it?
  1. Is your [Appointment Kept] Field a Yes/No Field?
  2. Copy and Paste your Expression as it currently exists in the Control Source Property of the Text Box.
Oct 3 '08 #6
plaguna
58 New Member
Yes, [Appointment Kept] Field is a Yes/No Field. And, I did copy and paste it into the Control Source Property of the Text Box. Also, I tried replacing other fields with different data types, modifying your expression, and I get the same result: #Error.

plaguna
Oct 3 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Plaguna. ADezii has asked more than once if your [Appointment Kept] field is a Yes/No field - one in which there can only be two values, True and False, or Yes and No (representing True and False). You have affirmed that it is - but your posts suggest to me that it is a Text field containing the text values 'Yes' or 'No'.

These are NOT the same as the logical values Yes and No, which in Access are constants - the constant Yes equating to -1 and the constant No equating to 0. Two possibilities: your [Appointment Kept] field really is a Yes/No field, in which case using [Appointment Kept] = 'Yes' in the Dcount is an error, or it is a text field, in which case trying to use [Appointment Kept] = True in the DCount is an error.

It will help us greatly if you could please confirm what type the field really is. ADezii's suggested code should work fine if your Yes/No fields really are boolean Yes/No fields, and not text.

I attach a screenshot of a single Yes/No field as you would see it in table design view so you can be certain whether or not it really is a yes/no field.

-Stewart
Attached Images
 
Oct 3 '08 #8
plaguna
58 New Member
Thank you guys for helping,
Yes, [Appointment Kept] field is a Yes/No Field. Probably, I was not clear that I changed it. It Is not a Text Data Type any more. Even though, I still have the #Error output

plaguna
Oct 3 '08 #9
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Ok, so it was text (as I thought) but now it isn't. Yet you were referring in what you posted most recently to a text 'Yes' value, NOT the boolean constant Yes.

Forgetting the percentage for a moment, please advise what happens when you try just one DCount from ADezii's post 4 as the rowsource for your textbox:

Expand|Select|Wrap|Line Numbers
  1. =DCount("*", "[BDC Information]", "[Appointment Kept] = True And [Internet Source Salesperson] = 'AutoTrader'") 
Please copy and paste this exactly as shown - DO NOT PUT 'Yes' IN PLACE OF True as you appear to have done at other times. This should simply return the count of the number of Autotrader listings where appointment kept is true.

-Stewart
Oct 3 '08 #10
plaguna
58 New Member
I just copied and pasted as you said. I checked every single character, and I still have the #Error output
Oct 3 '08 #11
ADezii
8,834 Recognized Expert Expert
I just copied and pasted as you said. I checked every single character, and I still have the #Error output
plaguna, there seems only 1 Option left at this point. If I provide my personal E-Mail Address in a Private Message, would you be willing to send me the Database, or a subset of it, as an E-Mail Attachment?

@Stewart, thanks for the assist in this Thread.
Oct 3 '08 #12
plaguna
58 New Member
plaguna, there seems only 1 Option left at this point. If I provide my personal E-Mail Address in a Private Message, would you be willing to send me the Database, or a subset of it, as an E-Mail Attachment?

@Stewart, thanks for the assist in this Thread.
Sure, that will be great. But, do you thing if I get your email address, I can sent it to you tomorrow night? My company is closing in a few minutes and I won’t be able to do it until then. If you don’t mind. That will be wonderful, because I’m trying to do this for too long.

I really appreciate it

plaguna
Oct 3 '08 #13
ADezii
8,834 Recognized Expert Expert
Sure, that will be great. But, do you thing if I get your email address, I can sent it to you tomorrow night? My company is closing in a few minutes and I won’t be able to do it until then. If you don’t mind. That will be wonderful, because I’m trying to do this for too long.

I really appreciate it

plaguna
I'll send it to you in a Private Message in 5 minutes (6:45 P.M.).
Oct 3 '08 #14
plaguna
58 New Member
I'll send it to you in a Private Message in 5 minutes (6:45 P.M.).
I sent you two files: The file that I'm working on and a test file. I'm sorry for the delay. thank you in advance

plaguna
Oct 6 '08 #15
ADezii
8,834 Recognized Expert Expert
I sent you two files: The file that I'm working on and a test file. I'm sorry for the delay. thank you in advance

plaguna
The answer to your dilemma is quite obvious. In info_test.mdb, where the code is functional, you have an Info Table consisting of the [Source](TEXT 255) and [App Kept](Yes/No) Fields. In your Production Database (BDC_Information.mdb), this Table (Info Table), does not even exist. The Expression used for the Control Source of the Text Box relies entirely on the Fields within the Info Table (No Table ==> No Fields ==> Error!).
Oct 6 '08 #16
plaguna
58 New Member
You are right, It was a miss spelled. Instead of “BDC Info Table” It was “DBC Info Table” and of course It couldn’t fine It. Now I don’t have a #Error message anymore, but the output is not correct. It doesn’t count correctly when the report is by groups. Even if the expression is in the Report Footer.

plaguna
Oct 6 '08 #17
plaguna
58 New Member
Please let me rephrase the last part of my last post. The expression I got from ADezii and Stewart Ross Inverness does count only in the Report Footer. In fact, It works beautifully, which is great. But, when I try it in the Group Footer, It gives Grand totals. (the same output as the Report Footer) How can I get the total for each group?

Thank you
plaguna
Oct 6 '08 #18
ADezii
8,834 Recognized Expert Expert
Please let me rephrase the last part of my last post. The expression I got from ADezii and Stewart Ross Inverness does count only in the Report Footer. In fact, It works beautifully, which is great. But, when I try it in the Group Footer, It gives Grand totals. (the same output as the Report Footer) How can I get the total for each group?

Thank you
plaguna
plaguna, you change the Data Type of a Field and don't tell us, the Table used in the Expression to calculate the Grand Totals contains References to a Table that doesn't even exist in the Production Database, and now you tell us it is not 'Grand Totals' that you are looking for but 'Group Totals'. To be frank, I'm almost at the ropes end on this one. I'll make one more attempt to solve this problem given the continuously changing Parameters.
Oct 6 '08 #19
ADezii
8,834 Recognized Expert Expert
Please let me rephrase the last part of my last post. The expression I got from ADezii and Stewart Ross Inverness does count only in the Report Footer. In fact, It works beautifully, which is great. But, when I try it in the Group Footer, It gives Grand totals. (the same output as the Report Footer) How can I get the total for each group?

Thank you
plaguna
Here is the Final Solution which is rather far removed from what was initially envisioned. Group Percentages can now be calculated as requested. The following Expression was placed in a Text Box in the Location ID Group Footer of the BCD By Internet Source Report. I will return the Production Database back to you with all the corrections via my Private E-Mail Account. Good Luck.
Expand|Select|Wrap|Line Numbers
  1. =Format$(DCount("*","DBC Information Query","[Internet Source] _
  2. = 'AutoTrader' And [Appointment Kept] = True And [Location ID] = " & _
  3. [Combo23])/DCount("*","DBC Information Query","[Internet Source] _
  4. = 'AutoTrader' "),"Percent")
Oct 7 '08 #20
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Plaguna. I would ask that you reflect on ADezii's comments in his most recent posts. ADezii has gone the extra mile in assisting you - despite the changes in actual against stated conditions between posts which make it very hard to assist you from afar.

Words are very important to us - all we have to go on is what you tell us, and there is a world of a difference in a Grand Total and a Group Total. Similarly, we expect that users do not present us with SQL that is stacked with errors that should not be there - such as references to non-existent tables which basic testing would have revealed straight away. To expect us to work with such flawed material is simply inappropriate, whatever the level of user experience involved.

I trust that you will review the revised database provided by ADezii and recognise that further changes or developments are now up to you, given the base of the excellent support which you have received in this thread.

Kind regards

Stewart
Oct 7 '08 #21
plaguna
58 New Member
You guys are right. I reviewed all the previous posts, and I see some inconsistencies from my part. I agree with Stewart saying “Words are very important to us - all we have to go on is what you tell us”. I’m sorry that I fixed errors and made some changes along the way after the suggestions you tell me to do, and I didn’t let you know the updates. Now I understand that this way, you can get crazy trying to figure it out what is going on. Next time, I’ll consider more of what you need to know to help us, instead of thinking only about fixing the problem.

I always appreciate your help

plaguna
Oct 7 '08 #22
plaguna
58 New Member
I recreated this database file from scratch. The first one had too many inconsistencies and, was hard to follow when errors occurred.
I read about DCount () and, found that this function is to return the number of records specified, but it is good to use it in Queries. It is not recommended to use DCount() in a Report if you want to calculate from records in your report or report section.
Instead, I got this expression which works perfectly in a Group Totals and Grand Totals:
Code:
=Sum(Abs([Appointment Kept] = True And [Internet Source] = "AutoUSA"))

plaguna
Oct 10 '08 #23
ADezii
8,834 Recognized Expert Expert
I recreated this database file from scratch. The first one had too many inconsistencies and, was hard to follow when errors occurred.
I read about DCount () and, found that this function is to return the number of records specified, but it is good to use it in Queries. It is not recommended to use DCount() in a Report if you want to calculate from records in your report or report section.
Instead, I got this expression which works perfectly in a Group Totals and Grand Totals:
Code:
=Sum(Abs([Appointment Kept] = True And [Internet Source] = "AutoUSA"))

plaguna
Nice solution, thanks for sharing it with us.
Oct 10 '08 #24

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

Similar topics

3
2946
by: Matthias Haffke | last post by:
Ok, this is a tricky question for the pro's: My access sheet: line, id a, id b, val% ---------------- 1, a, ac, 0.04 2, a, ac, 0.28 3, a, ac, 0.015 4, a, ac, 0.205
1
2392
by: JMCN | last post by:
hello- i have created a tabular form using records from a specific query. then users will filter out the specific data. the next step is to take the count of the current records (daily open...
3
1972
by: Rabun | last post by:
Heres one that is giving me fits ( = = Access newbie), more than likely something simple that I blew right over . . . any help is appreciated - I have a report based on a query, with several...
18
2433
by: damezumari | last post by:
I would like to know how many of the visitors to my site has js enabled and how many has it turned off. I haven't found a simple solution searching Google groups so I suggest the following using...
2
12058
by: Pete | last post by:
I need to create a single query (Not a SQL query) against a single table that counts the number of records in the table, where the single field "tmp" contains specific string values If the field...
4
5644
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
1
1877
by: N06149 | last post by:
I have a report based on a query. I list an Org_Type then Org_Name then the Projects associated with it. Sample of report below: Community Type...
0
8162
denny1824
by: denny1824 | last post by:
I have a crystal report that someone else wrote and already has a Formula Field if Criteria then (Count ({FirstField},{SecondField}) / Count ({FirstField})) When the Criteria is true, this...
4
4831
by: zoeb | last post by:
Hi. I have a form which the user enters 2 years worth of data into (one record per year). The aim, is to populate the table this form is based on with 3 more years worth of data (i.e. creating 3...
0
7228
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,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7058
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...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4715
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...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
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 ...
0
426
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...

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.