Results 1 to 9 of 9
  1. #1
    russweb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    4

    Question A summing query?

    I know I should be able to do this but...


    I have a large column with the number of times different drugs have been prescribed. Each time a drug has been prescribed it is in the list.
    I want to run a simple query which tells me the frequency of the values - i.e. that paracetamol was prescribed 184 times, codeine 73 times etc.

    Please tell me in idiot speak how to do this.

    Manythanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    1. build GROUP BY (totals) query - query in design view, click Totals button (looks like Sigma) - group on the drug name and use Count function

    or

    2. build a report and use Grouping and Sorting with aggregate calcs - report will allow display of detail records and summary calcs

    These are basic Access functionality and Access Help has guidelines, also lots of web tutorials.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    russweb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    4
    Quote Originally Posted by June7 View Post
    1. build GROUP BY (totals) query - query in design view, click Totals button (looks like Sigma) - group on the drug name and use Count function

    or

    2. build a report and use Grouping and Sorting with aggregate calcs - report will allow display of detail records and summary calcs

    These are basic Access functionality and Access Help has guidelines, also lots of web tutorials.
    Jane
    That's really helpful. Can you point me to good tutorial. I am doing report as you recommended.
    I've added a group to the drug name which gives me name plus number of duplications for each time a specific patient is prescribed the same drug.
    Now I want it to count the number of different patients which are prescribed each drug.
    I have added drug name field as group.
    I then added patient field as sort - what function/calculation do I need to do?

    Thank you very much for your help.

    I am used to SPSS where I would just ask for frequency

    Hope you can help!

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Till June's back, just check out if below gives some guidelines :

    Code:
    SELECT 
    	qryDistinctDrugsPatient.Drug, 
    	Count(qryDistinctDrugsPatient.PatientID) AS CountOfPatientID
    FROM 
    (
    	SELECT DISTINCT 
    		tblPatientsDrugs.Drug, 
    		tblPatientsDrugs.PatientID
    	FROM 
    		tblPatientsDrugs
    )
    AS 
    qryDistinctDrugsPatient
    GROUP BY 
    	qryDistinctDrugsPatient.Drug;
    Thanks

  5. #5
    russweb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    4
    Thanks very much.
    Sorry, but I have no idea where to start with this. I am at such a low level, that I am only used to basic create table, query, report wizards.
    Don't know where I should start entering this code.
    Apologies for being a dumbo!

    (I should have said I'm using Access 2010)

  6. #6
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Method 1 :
    Open a new Query Design Window & go in to its SQL view. Copy Paste the Query which I have posted, after replacing tblPatientsDrugs with your table name & Drug & PatientID with your corresponding field names.

    Method 2 :
    In your Query Builder View, first build the sub-query qryDistinctDrugsPatient & save it. Then use the sub-query to build the final query.

    Let us know, if you face any problem in understanding above.

    Thanks

  7. #7
    russweb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    4
    Thanks again.

    I am trying Method 2 and am interrogating the query.

    As you know, I just want to count how many times the different drugs are prescribed.

    Click image for larger version. 

Name:	Access1.JPG 
Views:	4 
Size:	29.5 KB 
ID:	6898

    And this is it in the report view:

    Click image for larger version. 

Name:	Access 2.JPG 
Views:	4 
Size:	67.5 KB 
ID:	6899

    I can't get my head around why it needs such a complex approach just to count the different values in a field...

    May have to give up. but thanks for all your help and time

  8. #8
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Quote Originally Posted by russweb View Post
    As you know, I just want to count how many times the different drugs are prescribed.
    If I have understood correctly, you "want to count how many times the different drugs are prescribed.",
    but want to count a Patient as 1, if the same drug has been prescribed to him / her multiple times.
    For eg. :
    Drug "A" has been prescribed to Patient "Tom" twice & to "Ben" once. You wan't the Count of Patients for Drug "A", to be considered as 2 and not 3.

    Was not able to understand the Query Design View you have attached.

    Quote Originally Posted by russweb View Post
    May have to give up.
    ???

    Are you facing difficulty in using the Query Design View.
    If yes, Just post your table structure (the table name & the field names), & am sure someone should be able to get you on the way.

    Thanks

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Or you can see if the report can accomplish this with the raw data.

    Group by drug section. Patients in detail section. Textbox in drug group section footer: =Count(PatientID).

    A complication arises if each patient can have more than prescription for the same drug.

    Again Access Help has guidelines. Tutorials on web. Bookstore.

    http://office.microsoft.com/en-us/ac...001159160.aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. A simple question:
    By kosti in forum Queries
    Replies: 4
    Last Post: 10-12-2011, 11:46 AM
  2. Simple VBA Question
    By koper in forum Access
    Replies: 1
    Last Post: 01-20-2011, 12:07 PM
  3. Simple question
    By KenM in forum Queries
    Replies: 1
    Last Post: 11-10-2009, 03:32 PM
  4. Simple question?
    By roads.zx in forum Access
    Replies: 0
    Last Post: 10-15-2009, 04:56 PM
  5. Very simple question!
    By fiddley in forum Programming
    Replies: 2
    Last Post: 04-28-2009, 02:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums