Results 1 to 7 of 7
  1. #1
    Jgk is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    46

    Query to Filter Last Month or Current Month Totals - DateDiff or Dlookup expression

    SELECT [Billing Hours All].Project, Sum(CCur([BillableHours])*([InvoiceRate])) AS [Total Invoiced], Sum(CCur([BillableHours])*([BillingRate])) AS [Total Contractor Pay], Sum([Billing Hours All].BillableHours) AS [Total Hours Billed], Sum(CCur([BillableHours])*([BillingRate])) AS [Current Contractor Pay], Sum(CCur([BillableHours])*([InvoiceRate])) AS [Current Month Invoice], Sum([Billing Hours All].BILLABLEHOURS) AS [Current Month Hours]
    FROM [Billing Hours All]-
    GROUP BY [Billing Hours All].Project;

    The bold part of sql is what I need help with want it to filter data in table for last month data for each category- Contractor Pay, Month Invoice, Current Month Hours by Project

    I have the first part for Totals working- Total Invoiced, Total Contractor Pay, Total Hours Billed- by Project

    Thanks,

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Apply filter criteria to the query.

    WHERE Format([date field],"yyyymm") = Format(DateAdd("m",-1,Date()),"yyyymm")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Jgk is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    46
    WHERE Format([date worked],"yyyymm") = Format(DateAdd("m",-1,Date()),"yyyymm") I changed date field to my field name which is date worked and could not get it to filter data gave total billing for all projects. What am I doing wrong, Thanks for your help

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Is your qry a Select qry, a Crosstab, are you using Totals?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Don't know why it is doing that. You have the query grouping by project then it should show totals for each project, limited to the period of the WHERE clause.

    Post the entire revised SQL statement.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Jgk is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    46
    SELECT Projects.*, [Project Hours].ID, [Project Hours].*, [Contractors Extended].[Contractor Name], [Contractors Extended].BillingRate, nz([BillableHours])*nz([BillingRate]) AS Amount, Customers.InvoiceRate, CCur([BillableHours])*nz([InvoiceRate]) AS Invoice
    FROM (Customers RIGHT JOIN Projects ON Customers.ID = Projects.Customer) INNER JOIN ([Project Hours] INNER JOIN [Contractors Extended] ON [Project Hours].Contractor = [Contractors Extended].ID) ON Projects.ID = [Project Hours].Project
    ORDER BY [Project Hours].ID;

    This is query I edited :

    SELECT [Billing Hours All].Project, Sum(CCur([BillableHours])*([InvoiceRate])) AS [Total Invoiced], Sum(CCur([BillableHours])*([BillingRate])) AS [Total Contractor Pay], Sum([Billing Hours All].BillableHours) AS [Total Hours Billed], Sum(CCur([BillableHours])*([BillingRate])) AS [Current Contractor Pay], Sum(CCur([BillableHours])*([InvoiceRate])) AS [Current Month Invoice], Sum([Billing Hours All].BILLABLEHOURS) AS [Current Month Hours]
    FROM [Billing Hours All]
    WHERE Format([date worked],"yyyymm") = Format(DateAdd("m",-1,Date()),"yyyymm")
    GROUP BY [Billing Hours All].Project;

    Project Total Contractor Pay Total Invoiced Total Hours Billed Current Contractor Pay Current Month Invoice Current Month Hours
    1009 $1,194.50 $0.00 29.25 $1,194.50 $0.00 29.25
    1014 $5,940.00 $0.00 148.5 $5,940.00 $0.00 148.5
    1250 $972.00 $3,225.00 43 $972.00 $3,225.00 43
    1254 $120.00 $195.00 3 $120.00 $195.00 3
    1256 $140.00 $227.50 3.5 $140.00 $227.50 3.5

    In order for query to give results, I enter April 2014 and in my test company get this, which is totals. Thanks

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    What do you mean by 'enter April 2014' - enter where?


    If you want to filter to a single month then the query can only show data summarized for that month. If Total Invoiced and Total Hours Billed are supposed to be for more than the current month (YTD?), can't do that all in the same GROUP BY.

    Perhaps you should build a report and do summary calcs in report and group header/footer sections.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 43
    Last Post: 08-06-2014, 08:21 PM
  2. Query Expression for Month Names
    By tngirl in forum Queries
    Replies: 1
    Last Post: 03-06-2014, 01:52 PM
  3. Query for current month and year onward
    By tylerg11 in forum Queries
    Replies: 1
    Last Post: 12-30-2013, 12:10 PM
  4. Current Month/Year Query
    By Roadbeer in forum Queries
    Replies: 3
    Last Post: 06-17-2013, 01:20 PM
  5. query to sum totals for month using sql
    By Ecal in forum Queries
    Replies: 1
    Last Post: 05-16-2013, 05:08 PM

Tags for this Thread

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