• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

Reset Running Sum at year end.

How can I reset total at year end and start over at 1st January from next year? Follwing is my SQL statment from Query "Weeklyrunsum".


SELECT W.WDate AS WYDate, Format(Sum(W.NSales),"Fixed") AS NSales, (SELECT Format(Sum(A.NSales),"Fixed") FROM [WeeklyGroupQuery] AS A WHERE A.WDate <=W.WDate) AS RunningTotal
FROM WeeklyGroupQuery AS W
GROUP BY W.WDate
ORDER BY W.WDate;
0
perrypshah
Asked:
perrypshah
  • 8
  • 8
1 Solution
 
jadedataMS Access Systems CreatorCommented:
run it as two separate queries,
then bring them back together with a union query
0
 
perrypshahAuthor Commented:
I have table with four years data how can ?I have sepreat query with runnig sum reset at each year end?
0
 
jadedataMS Access Systems CreatorCommented:
build the query to be specific to each year, four times.

The patterns in this exercise can be noted and used to build a vba routine that could

  determine what years are available in the data
  run the query once for each year
  store/report the results of each year
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
perrypshahAuthor Commented:
can you direct me to sample SQL Statments? for  yearly data query.
0
 
jadedataMS Access Systems CreatorCommented:
determine which years are available
  select distinct year(W.WDate) as AvailableYear FROM Tablename Group BY year(W.WDate);

SELECT W.WDate AS WYDate, Format(Sum(W.NSales),"Fixed") AS NSales, (SELECT Format(Sum(A.NSales),"Fixed") FROM [WeeklyGroupQuery] AS A WHERE A.WDate <=W.WDate) AS RunningTotal
FROM WeeklyGroupQuery AS W
WHERE (year(W.WDate)=2004)
GROUP BY W.WDate

(the above presumes that you had the rest of the query working before...)

I also feel compelled to point out that this could/should be done in an Access report format that will do the running sum over specified groups like the Year the data pertains to, by including the year(w.wdate) expression as a field in the recordsource.

Access Queries require inordinate effort to get correct running sums.  Reports do them by design

0
 
perrypshahAuthor Commented:
Above Sql statment brings data like following.

WYDate         NSales              RunningTotal
1/3/04           5551.95            722796.35
1/10/04        12659.26           735455.61

I need "RunningTotal" As following

WYDate         NSales              RunningTotal
1/3/04           5551.95            5551.95
1/10/04        12659.26           18211.21

How can I achive above result?
0
 
jadedataMS Access Systems CreatorCommented:
queries to not perform running sums, you will need to write a function that can do this based on the year and the "cut-off" date.

or as I said earlier, run the output to a report format that does running sums easily
0
 
perrypshahAuthor Commented:
Which function on report is it DSum? or Control Source Running Sum "Yes"?
0
 
jadedataMS Access Systems CreatorCommented:
See "RunningSum" in the help system.

DSum is not the right tool for the job.
0
 
perrypshahAuthor Commented:
It dose not tell me how to get "YEAR TO DATE" sum from table or query. It can do RunningSum of texbox located on Report It self. Is there any way to get YTD data summed up on Report?
0
 
ehartfield2002Commented:
Have your report group by Year(WYDate).  Then your control will only sum over a single year.
0
 
perrypshahAuthor Commented:
I have Table name "Dunkin Sales" has following fields

No (PK)
Date
Shift1
Customer Count1
Shift2
Customer Count2
Gross Sales
Tax
Customer Count3
Cash Expanse

I would like to get Data for comperision of [Gross Sales]-[Tax] = [Net Sales] Last year Vs. This year on Date 06/19/2003 Vs. 06/19/2004 (Year To Date)  how do I get this in my report? So I can track sales tren up or down.  
0
 
jadedataMS Access Systems CreatorCommented:
How does the above bear on the original question of getting running sums to work???
0
 
perrypshahAuthor Commented:
Jadedata,

Your suggestion is directing me to change my question and I have also incress points. End result of the question is to get YTD running sum of net sales in report "Fee Card".
0
 
jadedataMS Access Systems CreatorCommented:
Running sum is not necessarily the same as a YTD total, and the two may not be able to exist in the same query depending on other conditions of the query.

0
 
perrypshahAuthor Commented:
I am more Interested in YTD NOT necessary in Running Sum I thought I can achieve YTD by Achieving Running Sum.
0
 
jadedataMS Access Systems CreatorCommented:
YTD is basically

  SELECT Sum([Field1]) as sField1 FROM Tablename Where ([DateField] between #1/1/2004# and #8/1/2004#)

running sum is the continuous updating of that total as the query rolls forward from days to day or week to week, constantly updating the total as it goes....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now