?
Solved

How do I count records from a Statement, however if the same record is multiple, then count them together

Posted on 2015-02-06
14
Medium Priority
?
81 Views
Last Modified: 2015-02-08
want to show a count of some records

however some records values will be the same, so I want these counted as multiple.

eg
SYD 1
MEL 2
DPS 4

not
SYD
MEL
DPS
MEL
DPS
DPS
DPS

is there a way of showing this?
0
Comment
Question by:Graeme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1200 total points
ID: 40595082
using a query

select [FieldName], Count([FieldName])
from tableName
group by  [FieldName]
0
 

Author Comment

by:Graeme
ID: 40595090
Thanks for that I have correct my query so that it works

Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")                                          

How do I show the count of each record?

eg
SYD 1
MEL 2
DPS 4
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595092
You can also try:
select distinct  [FieldName], Count([FieldName]) from tableName
group by  [FieldName]
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595095
Or
select count(distinct FieldName), FieldName
from tableName
group by  FieldName
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40595097
Since this is just a simple function in access, I might suggest using the query wizard to find Duplicates.
Then you may modify the query by removing the >1 criteria, either in design view or sql view.

This helps in improving your access programming. You may modify the query to get other functions, like Sum or Count, by replqacing Count or adding to it.
0
 

Author Comment

by:Graeme
ID: 40595159
Hey all, just need the code to show the records and how many of each
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40595214
where do you want to show the records?
0
 

Author Comment

by:Graeme
ID: 40595216
As a list

eg
SYD 1
MEL 2
DPS 4

is this what you meant?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40595225
As a list , where ?
0
 

Author Comment

by:Graeme
ID: 40595244
Sorry I do not get what you mean by 'where' ?

Here is the code:

<%
Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")							
%>
	<tr>
		<td colspan=8 align=center>Destinations</td>
		<td colspan=2>&nbsp;</td>
	</tr>
	<tr>
		<td height=20 width=20% colspan=2>0%</td>
		<td height=20 width=20% colspan=2>25%</td>
		<td height=20 width=20% colspan=2>50%</td>
		<td height=20 width=20% colspan=2>75%</td>
		<td height=20 width=20% colspan=2>100%</td>
	</tr>
<%
	Do While Not KPIsDest.eof
%>
	<tr>
		<td colspan=8>
			<table width=100% border=0>
				<tr>
					<td height=20 bgcolor=black width=<%=FormatNumber(((!!!!!!!/EnqCount)*100),2)%>%></td>
					<td height=20>&nbsp;</td>
				 </tr>
			</table>
		</td>
		<td><%=KPIsDest("enq_dest")%></td>
		<td><%=FormatNumber(((!!!!!!!!!/EnqCount)*100),2)%>% Destinations Strikerate</td>
	</tr>
<%
	KPIsDest.MoveNext 
		LOOP
	KPIsDest.Close
%>

Open in new window


where i have the !!!!! is where i need the sum count total of the destinations
0
 
LVL 85
ID: 40595489
So you want to show this on a web page. That's what Rey was asking. We don't know what programming environment you're using, so asking us "how to  show a list" doesn't make much sense to us.

You'd have to loop through the recordset and add rows to your table:

Do Until kpIsDest.EOF
<tr>
            <td colspan=8>
                  <table width=100% border=0>
                        <tr>
                              <td height=20 bgcolor=black width=<%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>%></td>
                              <td height=20>&nbsp;</td>
                         </tr>
                  </table>
            </td>
            <td><%=KPIsDest("enq_dest")%></td>
            <td><%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>% Destinations Strikerate</td>
      </tr>
Loop
0
 

Author Comment

by:Graeme
ID: 40596718
hello and thanks for clarifying...

KPIsDest("YourNumberColumn") being what ?

what do you need from me to figure out which column i am looking for?
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 800 total points
ID: 40596749
YourNumbercolumn is the column from your SQL statement which would contain the value you want to show. It would be either "eng_dest", or the COUNT(eng_dest) column. Since I assume it's the COUNT column, you might change the SELECT statement to this:

SELECT enq_dest, COUNT(enq_dest) AS DestCount FROM enq WHERE enq_date etc etc

Then refer to it like this:

kpIsDest("DestCount")
0
 

Author Closing Comment

by:Graeme
ID: 40597492
Cheers all for your help!

works a treat!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 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