Solved

Reset Running Sum at year end.

Posted on 2004-08-01
19
257 Views
Last Modified: 2012-08-13
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
Comment
Question by:perrypshah
  • 8
  • 8
19 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 11688566
run it as two separate queries,
then bring them back together with a union query
0
 

Author Comment

by:perrypshah
ID: 11688708
I have table with four years data how can ?I have sepreat query with runnig sum reset at each year end?
0
 
LVL 32

Expert Comment

by:jadedata
ID: 11688865
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
 

Author Comment

by:perrypshah
ID: 11689037
can you direct me to sample SQL Statments? for  yearly data query.
0
 
LVL 32

Accepted Solution

by:
jadedata earned 125 total points
ID: 11689101
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
 

Author Comment

by:perrypshah
ID: 11689122
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
 
LVL 32

Expert Comment

by:jadedata
ID: 11689135
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
 

Author Comment

by:perrypshah
ID: 11689145
Which function on report is it DSum? or Control Source Running Sum "Yes"?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 32

Expert Comment

by:jadedata
ID: 11689182
See "RunningSum" in the help system.

DSum is not the right tool for the job.
0
 

Author Comment

by:perrypshah
ID: 11689206
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
 
LVL 3

Expert Comment

by:ehartfield2002
ID: 11689509
Have your report group by Year(WYDate).  Then your control will only sum over a single year.
0
 

Author Comment

by:perrypshah
ID: 11689601
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
 
LVL 32

Expert Comment

by:jadedata
ID: 11689742
How does the above bear on the original question of getting running sums to work???
0
 

Author Comment

by:perrypshah
ID: 11689762
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
 
LVL 32

Expert Comment

by:jadedata
ID: 11689802
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
 

Author Comment

by:perrypshah
ID: 11689823
I am more Interested in YTD NOT necessary in Running Sum I thought I can achieve YTD by Achieving Running Sum.
0
 
LVL 32

Expert Comment

by:jadedata
ID: 11690129
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

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now