Results 1 to 2 of 2
  1. #1
    ASWilliams is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2016
    Posts
    10

    Sum of Week Totals

    Hello Access Forum,



    I have a database on SQL Server for which I will be creating a front end in Access. I currently need a query that is proving difficult for me write.

    I have a Volumes table with columns [AccNo], [ISOWeek], and [Volume]. I have another table that stores basic account information; the key columns for this post are [AccNo] and [StartDate]. What I need is the total annualised volume for customers with a start date 52 weeks old or greater than a specified ISO week. What I need my query to do is this:


    1. Loop through each of the 52 weeks in a year
    2. for each week, determine which accounts have a start date 52 weeks or greater
    3. sum the volume for all accounts, based on their start date (as in point 2)
    4. sum the total of sums to generated the annualised total volume.


    I'm able to convert dates to ISO Weeks and write the conditional statements to identify the accounts I need. The big I'm struggling with is how to effectively loop through each week (rather than get the account status for a single week, then sum the volume for those​ accounts over a year - this would be incorrect).

    Any advise on what kind of query construct(s) I need on this will be much appreciated. I'm guessing there's going to be a subquery or two, but I'm not quite sure where to start.

    Many thanks in advance

  2. #2
    ASWilliams is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2016
    Posts
    10
    I've managed to find a solution to this problem by using CROSS APPLY:

    I first created a table variable containing all the week numbers I need to search. I then created a table-valued function that returns all the account numbers identified as having a start date that meets the criteria for the given week. I then use:


    Code:
    SELECT *
    FROM @WeekNumbers
    CROSS APPLY fn_myFunction
    This essentially runs the function (returning a table) for each week number in the @WeekNumbers table.

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

Similar Threads

  1. Replies: 26
    Last Post: 11-05-2015, 01:58 PM
  2. Replies: 9
    Last Post: 06-19-2015, 03:37 PM
  3. Divide Period Budget Totals by Week
    By Dorothy in forum Database Design
    Replies: 0
    Last Post: 07-22-2013, 05:42 PM
  4. Week Totals
    By Azyrus in forum Reports
    Replies: 2
    Last Post: 06-26-2011, 04:21 PM
  5. Day of Week Totals
    By ddog171 in forum Queries
    Replies: 1
    Last Post: 03-18-2006, 07:01 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