Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display totals for each week

Status
Not open for further replies.

codegirl

Technical User
Feb 9, 2003
13
US
To simplify my question, say I have a table called Invoices and the only two fields are Invoice_Date and Total. I want to display a list which lists the week ending date and the sum of the invoice totals for the week. The list needs to contain every week, not just the current week. Is there a way to do this in SQL, or should I do it in my VB code? Thanks!!
 
You will need a Totals query. In your query put this expression in the first column
MyWeek:[Invoice_Date] - Weekday([Invoice_Date]) +1
then in the next column add your Total field
Turn on the Totals, View...Totals on the menu bar. Group By MyWeek and Sum the Total field.

This should get you close.

Paul
 
Actually I need a SQL command to put in my VB program... do you know how to convert that to SQL? Thanks!
 
Dim strSQL as String
strSQL = "SELECT [Invoice_Date]-Weekday([Invoice_Date])+7 AS MyWeek, Sum([TableName].Total) AS SumOfTotal
FROM [TableName]
GROUP BY [Invoice_Date]-Weekday([Invoice_Date])+7"

Sorry I read it as Beginning of Week at first. To get the end of week you add 7 instead of 1.

This will not show weeks where there were no invoices.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top