+ Reply to Thread
Results 1 to 7 of 7

Twelve Trailing Period Query Help

  1. #1
    Registered User
    Join Date
    04-07-2011
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    19

    Twelve Trailing Period Query Help

    Hi guys,

    So I'm looking to create a query that will generate a dynamic report that sums each customer sales over the most recent 12 month window. As a new month of sales is completed, I need this query to add the most recent completed month, while dropping the last month in the range.

    I have a SerialMonth field added to my Date Table that allows me to use numeric values to signify which months I want in a given range. For example, November 2011 is SerialMonth 206, and December will be 207.

    Obviously if I want just a snapshot look at a range of 12 months I can include the criteria "Between 194 and 206" in the SerialMonth field to give me what I want, however when December rolls around I will have to manually edit that criteria to say "Between 195 and 207".

    Is there a way through criteria or SQL to give me the most recent 12 Months? Perhaps the TOP 12 included in my SQL statement?

    Any help is greatly appreciated!!

  2. #2
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Twelve Trailing Period Query Help

    If you're identifying the SerialMonth on a form so your query can use it as a calculation/data source, then how about:

    Please Login or Register  to view this content.
    or add a calculated field to your query for the same purpose.

    Cheers,
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  3. #3
    Registered User
    Join Date
    04-07-2011
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Twelve Trailing Period Query Help

    I'd like to keep it within the Query if possible, as this Query will most likely also be utilized as a source for an Excel file at some point. The code you listed does give the right logic, however I need it to look for the highest SerialMonth values in order to give me the most recent 12 month window. I threw in the Max() function but it does not seem to do the trick.

    Also, I know that throwing in the SerialMonth field into the query will give me a sum of sales for each month, when in the end I am looking for just a single sum of sales figure for each customer based on the criteria of the latest 12 months.

    Thank you for the help and quick reply

  4. #4
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Twelve Trailing Period Query Help

    How about a calculated field in the query that generates SerialMonth based on the NOW() function (SerialNowMonth)?

  5. #5
    Registered User
    Join Date
    04-07-2011
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Twelve Trailing Period Query Help

    Ahh, now here comes the tricky part. I used the term "Month" to dumb things down in looking for an answer to my question, however our sales data is logged in periods, as we run on 13 periods a year (4 weeks each). So, the NOW() function will not work because the periods can range between multiple months in some cases during the year.

  6. #6
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Twelve Trailing Period Query Help

    Okay... how are you numbering (and identifying) your weeks?

  7. #7
    Registered User
    Join Date
    04-07-2011
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Twelve Trailing Period Query Help

    For the current data tables I'm using, sales aren't broken down by individual transactions but rather summarized by period totals in order to minimize the number of records I am importing from our master sales database. So if I am understanding your question correctly, the source I am using does not have a field designating our weeks directly.

    In the back end, our weeks would be broken out I assume as {1, 2, 3, 4} for Period 1, followed by {1, 2, 3, 4} for Period 2, etc rather than a sequential numbering of 1-52.

    Let me know if I answered your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1