Results 1 to 3 of 3
  1. #1
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16

    Lightbulb Stats in Access - SQL

    Hi there,

    I've done some Googling on this but can't seem to work it out.

    I have a data set containing a number of organisation records. These records display a status and a date and the person responsible for calling to arrange a meeting with these organisations.





    Company Status Today's Date Caller
    a Booked 01/01/2019 1
    b Call Back 01/01/2019 2
    c Call Back 01/01/2019 1
    d Declined 01/01/2019 1
    e Booked 01/01/2019 2


    How can I achieve the following result with an SQL query? This should only show the results for where today's date = TODAY()

    Caller Count of 'Booked' Count of 'Call Back' and 'Declined' Count of 'Other'
    1 1 2 0
    2 1 1 0
    3 0 0 0


    Many thanks in advance!

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    First create an aggregate query by clicking the totals button on the ribbon.
    Add the 4 fields. Each will have Group By in the Totals row of the query design.
    Change that to Where for the date field and filter that for Date()
    Next change the Company field to Count
    Save the query and run it to check its working

    Now create a crosstab query based on the above to get the required result
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Looks like a CROSSTAB query.

    TRANSFORM Count(Calls.CallDate) AS CountOfCallDate
    SELECT Calls.Caller
    FROM Calls
    GROUP BY Calls.Caller
    PIVOT IIf([Status]="Call Back" Or [Status]="Declined","CallBack_Dec",IIf([Status]="Booked","Booked","Other")) In ("Booked","CallBack_Dec","Other");

    However, since there is no record for caller 3 there is record in the output. If you need to show all persons even if they did not make calls, join this query to a Persons table that has a unique record for each person.

    More about CROSSTAB http://allenbrowne.com/ser-67.html
    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. Compile Stats (number of records across several tables)
    By Bcanfield83 in forum Programming
    Replies: 4
    Last Post: 09-15-2018, 03:29 PM
  2. Soccer/Football stats
    By spyfire14 in forum Access
    Replies: 5
    Last Post: 05-24-2018, 12:48 AM
  3. Generating stats - newbie question
    By FavouredEnemy in forum Reports
    Replies: 3
    Last Post: 04-15-2010, 08:11 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