Solved

Reset Running Sum at year end.

Posted on 2004-08-01
19
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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
 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

739 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