Results 1 to 11 of 11
  1. #1
    Gooford is offline Novice
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    10

    Arrow Summing data between two dates (when the dates are different per record)

    Hi,



    I have a master table which shows all transactions per record (person) over a financial year.

    Each record person has a seperate package period over which their spend needs to be measured. Therefore although I have all their transactions for the year, I only want to sum their transactions between their given [start date] and [end date] which are in columns.

    I need to be able to create a field which sums all expenditure per record between the start and end dates

    Name Start Date End Date Invoice Date Amount

    Matt 15/5/11 15/9/11 1/11/11 £100
    Matt 15/5/11 15/9/11 7/7/11 £200
    Matt 15/5/11 15/9/11 12/12/11 £200

    In this case I would only want to sum 7/7/11 as this is between the start and end dates

    I want to write something like sumif([Invoice Date] is between [start date] and [end date] - not sure where or how exactly



    (the start date and end date will always be the same per person)

    Is this possible in access?

    Thanks and regards

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    How about putting a calculated field in a query. The calculated value is zero if outside the date range and the actual value if within the date range. Then you could run a sum on the calculated field.

  3. #3
    Gooford is offline Novice
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    10
    Quote Originally Posted by hertfordkc View Post
    How about putting a calculated field in a query. The calculated value is zero if outside the date range and the actual value if within the date range. Then you could run a sum on the calculated field.

    Hi,

    Thanks. How would I do that? (I'm fine with Excel but Access is fairly new to me)

    I've worked out how to do simple calculated fields but not what syntax to use to put in, if statements etc

  4. #4
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    I'm not on my Access computer, so this is unchecked. I use the query design view and datasheet view to check on results as I get into more complicated calculations.
    Say your query has fields, D1,D2,DT, Val1
    In the design view, show those fields and add field NewV.
    In the NewV field, NewV:iff(([DT]>=[D1]) AND [(DT]<=[D2]),Val1,0)
    That should give you a zero if outside the date range or a value if in the date range.
    Once you get that, add a sum on the NewV column and you are done.

  5. #5
    Gooford is offline Novice
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    10
    Quote Originally Posted by hertfordkc View Post
    I'm not on my Access computer, so this is unchecked. I use the query design view and datasheet view to check on results as I get into more complicated calculations.
    Say your query has fields, D1,D2,DT, Val1
    In the design view, show those fields and add field NewV.
    In the NewV field, NewV:iff(([DT]>=[D1]) AND [(DT]<=[D2]),Val1,0)
    That should give you a zero if outside the date range or a value if in the date range.
    Once you get that, add a sum on the NewV column and you are done.

    Thanks for helping. For some reason I am getting an #error message in the calculated field when I run the query

  6. #6
    Gooford is offline Novice
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    10
    Hi,

    The Column I create is returning an error -

    Expr1: IIf(([PAYMENT_TIME]>[Review Date]),0,[Amount])


    The Review Date comes from one table (Alphalist) and the rest of the info comes from Invoices table. They are linked by and ID number.

    The calculated field is returning #error and I cannot work out why. I can get other expressions to work, e.g if amount is less than 1000 then return 0, or if greater than then return 1.

    Any help much appreciated

  7. #7
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    What are the Data types for PAYMENT_TIME and [Review Date]? Is there a [Review Date] field in the Invoices table? Can you put the Data structure for the 2 tables here?

  8. #8
    Gooford is offline Novice
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    10
    PAYMENT_TIME had a date and time:-

    04/04/2011 15:57:17


    Review Date is just a date:-

    14/4/12

    I changed both fields in the properties to be SHORT DATE format but this hasnt stopped the error

  9. #9
    Gooford is offline Novice
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    10
    No there isnt a Review Date field in the Invoices table

  10. #10
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    temporarily Add the 2 fields to the query and make sure that the data matches what you think it should. Other than double checking the data I don't see anything wrong with your formula.

  11. #11
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    In addition to Ray's questions, may I suggest...

    Quote Originally Posted by Gooford View Post
    Hi,

    The Column I create is returning an error -

    Expr1: IIf(([PAYMENT_TIME]>[Review Date]),0,[Amount])


    The Review Date comes from one table (Alphalist) and the rest of the info comes from Invoices table. They are linked by and ID number.

    The calculated field is returning #error and I cannot work out why. I can get other expressions to work, e.g if amount is less than 1000 then return 0, or if greater than then return 1.

    Any help much appreciated
    --------------------------------------------------------------------------------------------------------------------------
    that 1) you qualify the field names with their table names, and
    2) if there is any chance of any of the fields being null, use the NZ function, e.g.
    iif((NZ(Tables![Invoices]![Payment_Time])>NZ(Tables![AlphaList]![Review Date]),0,NZ(Tables![Invoices]![Amount]))
    (Careful, I may have butchered the matching parenthesis)

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

Similar Threads

  1. Importing data based on dates
    By sentil in forum Programming
    Replies: 1
    Last Post: 07-09-2011, 01:56 AM
  2. display all dates between two dates
    By KenThompson in forum Access
    Replies: 8
    Last Post: 02-23-2011, 01:11 PM
  3. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 PM
  4. Replies: 0
    Last Post: 07-27-2009, 07:51 AM
  5. Having trouble with dates in my Data Base!!!!
    By BigPhil in forum Queries
    Replies: 4
    Last Post: 02-15-2006, 12:47 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