Results 1 to 8 of 8
  1. #1
    dargo72 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2012
    Posts
    53

    Count or Sum Query to Eventually Make Chart Report

    I have one table with 4 "date" fields which activites are scheduled to take place. Eventually, I'd like to run a report by day or month that shows the number of activities scheduled to be completed on that day or month.



    I am unsure how to structure the underlying query to pull all the dates and total them by the specific day or more likley month.

    Help?

    Thank you,

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    If you have many activities associated with something, that describes a one-to-many relationship which requires (by normalization rules) that each activity (and it's corresponding date) be a separate record in a table. For example, lets say that you have several activities related to an event. The tables would look something like this:

    tblEvents
    -pkEventID primary key, autonumber
    -txtEventName

    tblEventActivities
    -pkEventActivityID primary key, autonumber
    -fkEventID (foreign key to tblEvents)
    -dteActivity (activity date)
    -txtActivity

    So if you have 4 dates as you mention, with the above structure, you would have 4 records in tblEventActivities

    With this table structure, your query issue can be handled very easily.

  3. #3
    dargo72 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2012
    Posts
    53
    Splitting out the individual dates is not an option at this time.

    Assuming I had only one date that I wanted to run a report by month for, how would I do that in a query?

    Also, I can have 4 separate queries an then run a query of those to combine the reults, correct?

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    If you want your report to extract detail records by month, you would set up your query as follows

    SELECT month(datefield) as period, other fields...
    FROM tablename

    Then in your report you would set up a group level using the period field. Now, if your data spans more than one year & you want the report to include more than one year, then you will have to use the year() function in the query above and include an additional group level in your report. If you want the data for only 1 year, you will need to filter the above query for the year again using the year() function but using it in the WHERE clause of the query.

    If you want to do counts, you can do that in the period group level of the report.

    If you want to do the counting in the query directly rather than in the report, you would need an aggregate query based on the query shown above

    SELECT period, Count(somefield)
    FROM queryabove
    GROUP BY Period

  5. #5
    dargo72 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2012
    Posts
    53
    Quote Originally Posted by jzwp11 View Post
    If you want your report to extract detail records by month, you would set up your query as follows

    SELECT month(datefield) as period, other fields...
    FROM tablename

    Then in your report you would set up a group level using the period field. Now, if your data spans more than one year & you want the report to include more than one year, then you will have to use the year() function in the query above and include an additional group level in your report. If you want the data for only 1 year, you will need to filter the above query for the year again using the year() function but using it in the WHERE clause of the query.

    If you want to do counts, you can do that in the period group level of the report.

    If you want to do the counting in the query directly rather than in the report, you would need an aggregate query based on the query shown above

    SELECT period, Count(somefield)
    FROM queryabove
    GROUP BY Period
    I tried starting the query and put in this:

    Select Year([Stagegate Plan date] From [numbered steps])

    It is not working. Could you tell me what I'm missing.

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    When you run the query do you get an error or does it not return any data?

    What data type is the Stagegate Plan Date field?

  7. #7
    dargo72 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2012
    Posts
    53
    Quote Originally Posted by jzwp11 View Post
    When you run the query do you get an error or does it not return any data?

    What data type is the Stagegate Plan Date field?
    Error only.

    That field is a date/time field

  8. #8
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I see the problem. The closing parenthesis for the Year() function is in the wrong place

    Select Year([Stagegate Plan date] From [numbered steps] )

    It should be as follows:

    Select Year([Stagegate Plan date]) From [numbered steps]

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

Similar Threads

  1. Chart - Count of value
    By libraccess in forum Reports
    Replies: 2
    Last Post: 10-24-2012, 10:54 PM
  2. Make Chart From Query in Access 2007
    By James Parker in forum Access
    Replies: 6
    Last Post: 01-06-2012, 08:14 AM
  3. SQL Code to Make Query / Report
    By agent- in forum Programming
    Replies: 10
    Last Post: 06-17-2011, 04:14 PM
  4. Replies: 0
    Last Post: 03-26-2011, 09:59 AM
  5. make a chart from the table
    By barkarlo in forum Access
    Replies: 0
    Last Post: 07-29-2010, 02:22 PM

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