Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You want the record that has a date value equal to the last day of the month and the associated px_last value in that particular record?

  2. #17
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    BTW, the query you showed was incorrect

    you had this:

    SELECT DateAdd("d",1,DateSerial(Year([Period]),Month([Period]),1))-1 AS MonthEnd, px_last as Price
    FROM tbl_H15T10Y
    GROUP BY DateAdd("d",1,DateSerial(Year([Period]),Month([Period]),1))-1, px_last;

    It should be this

    SELECT dateadd("d", -1, dateserial(year(dateadd("m",1,period)),month(datea dd("m",1,period)),1)) as MonthEND, px_last as Price
    FROM tbl_H15T10Y

  3. #18
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Interestingly - this Query which takes a monthly average works perfectly:

    Code:
    SELECT DateAdd("m",1,DateSerial(Year([Period]),Month([Period]),1))-1 AS MonthEnd, AVG(px_last) AS Monthly_Avg
    FROM tbl_vix
    GROUP BY DateAdd("m",1,DateSerial(Year([Period]),Month([Period]),1))-1;
    It perplexes me that the query can find the month start and end values the take the average, but I am having so much trouble funding the month end number only.

  4. #19
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Quote Originally Posted by jzwp11 View Post
    You want the record that has a date value equal to the last day of the month and the associated px_last value in that particular record?
    That is exactly right

  5. #20
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    To find the price at the end of each month, you have to find when the period date = the end of the month date. So how about the following query. Note that there is no GROUP BY clause in the following query since you have no need to group records--you are trying to find specific records. This assumes that you have a record for the ending date of every month, if not the query will ignore that day

    SELECT tbl_H15T10Y.Period, dateadd("d", -1, dateserial(year(dateadd("m",1,period)),month(datea dd("m",1,period)),1)) as MonthEND, px_last as Price
    FROM tbl_H15T10Y
    WHERE tbl_H15T10Y.Period=dateadd("d", -1, dateserial(year(dateadd("m",1,period)),month(datea dd("m",1,period)),1))

  6. #21
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    This almost works, thanks jzwp11 - However if there is no datapoint for the last day of the month (if the last day of the month is a weekend) it ignores that month as you mentioned, can it find the last most value in that case, I am wondering if the max would work?

  7. #22
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    That will take a little more effort, so here goes

    Create a query that breaks out the year and month for each date in the table

    query name: qryPeriod
    SELECT Year(period) AS periodyear, Month(period) AS periodmonth, tbl_H15T10Y.period
    FROM tbl_H15T10Y;

    Next create an aggregate query using the query above

    query name: qryDateMaxByYearMonth

    SELECT qryPeriod.periodyear, qryPeriod.periodmonth, Max(qryPeriod.period) AS MaxOfperiod
    FROM qryPeriod
    GROUP BY qryPeriod.periodyear, qryPeriod.periodmonth;

    Now create a final query that joins the above qryDateMaxByYearMonth back to your original table

    query name: qryFinal

    SELECT tbl_H15T10Y.period, tbl_H15T10Y.px_last
    FROM tbl_H15T10Y INNER JOIN qryDateMaxByYearMonth ON tbl_H15T10Y.period = qryDateMaxByYearMonth.MaxOfperiod;

  8. #23
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    How do I run queries after the previous - should i be creating tables each time?
    (sorry newbie)

  9. #24
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Build and save each query as indicated. You only need to run the qryFinal; Access runs the others as it needs to when it runs qryFinal

  10. #25
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Thanks jzwp11 - that worked. I appreciate your help with this

    I am going to see if I can do some joining next, i.e. H15T10Y and H15T20Y and will keep you posted on how it turns out.

    Thanks again!

  11. #26
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome; glad you got this part worked out.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Join multiple tables to one
    By b6677862 in forum Queries
    Replies: 1
    Last Post: 02-08-2012, 06:59 AM
  2. Join for multiple tables?
    By Etownguy in forum Queries
    Replies: 3
    Last Post: 05-30-2011, 04:54 PM
  3. join date fields
    By rickscr in forum Database Design
    Replies: 4
    Last Post: 04-22-2011, 10:39 AM
  4. Multiple Table Join Issue
    By tehbaker in forum Database Design
    Replies: 4
    Last Post: 10-07-2010, 01:30 PM
  5. Error on Multiple Table Join & IIF
    By cmartin in forum Queries
    Replies: 1
    Last Post: 05-21-2010, 08:58 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