Hello all,
I am trying to create a running total based on a specific date range that is to be entered into a form.
I currently have the form set up with 2 text boxes (date1 and date2) which are the input for my start and end date, a table (tblALLBCPIC) with a DATE field and ORDPCK field (what I need a running sum of). There are other fields in the table but they shouldn’t matter.
Here is the SQL for my query so far:
SELECT tblALLBCPIC.DATE, tblALLBCPIC.ORDPCK, (SELECT Sum([ORDPCK]) FROM [tblALLBCPIC] AS [tblALLBCPIC_1] WHERE [tblALLBCPIC_1].[DATE] <= [tblALLBCPIC].[DATE]) AS RunningSum
FROM tblALLBCPIC;
I have added and played around with various configurations of this including adding
Between [FORMS]![frmBCPIC]![date1] And [FORMS]![frmBCPIC]![date2] into the criteria for the date field .
My results will usually give me a running total of the entire table (2005-2007) instead of for just the date range that was specified.
It is my understanding that the Dsum function will do pretty much the same thing but take much longer to calculate. ?
Another possible factor for failure so far is that the table with the data does have sum NULL fields/entries. I do know about the Nz function and am pretty sure something like this would work (Nz([ORDPCK],'0')) maybe somewhere.
Any help would be greatly appreciated. If you require any more info please let me know, thanks in advance.
12 8476
Something I have noticed in trying to figure out how to make this work is, that the function I am using is going through every record in my table to make the running sum/total.
Perhaps I need to use the Between date range criteria -
Between [FORMS]![frmBCPIC]![date1] And [FORMS]![frmBCPIC]![date2] in the running total function instead of in the criteria.
I will give that a try and see what happens.
Something I have noticed in trying to figure out how to make this work is, that the function I am using is going through every record in my table to make the running sum/total.
Perhaps I need to use the Between date range criteria -
Between [FORMS]![frmBCPIC]![date1] And [FORMS]![frmBCPIC]![date2] in the running total function instead of in the criteria.
I will give that a try and see what happens.
give this a testrun -
SELECT
-
tblALLBCPIC.DATE,
-
tblALLBCPIC.ORDPCK,
-
(SELECT Sum(nz([ORDPCK],0)) FROM [tblALLBCPIC] AS a HAVING a.[DATE] <= [tblALLBCPIC].[DATE]) AS RunningSum
-
FROM tblALLBCPIC
-
WHERE
-
format(tblALLBCPIC.DATE,"mm/dd/yyyy")
-
Between
-
format([FORMS]![frmBCPIC]![date1], "mm/dd/yyyy") And
-
format([FORMS]![frmBCPIC]![date2], "mm/dd/yyyy");
-
Thank you for taking the time to post a response, your assistance is very much appreciated.
give this a testrun -
SELECT
-
tblALLBCPIC.DATE,
-
tblALLBCPIC.ORDPCK,
-
(SELECT Sum(nz([ORDPCK],0)) FROM [tblALLBCPIC] AS a HAVING a.[DATE] <= [tblALLBCPIC].[DATE]) AS RunningSum
-
FROM tblALLBCPIC
-
WHERE
-
format(tblALLBCPIC.DATE,"mm/dd/yyyy")
-
Between
-
format([FORMS]![frmBCPIC]![date1], "mm/dd/yyyy") And
-
format([FORMS]![frmBCPIC]![date2], "mm/dd/yyyy");
-
I gave it a test run and it did not give me any results for the running total, and it still listed all records in the table instead of what was in the date range on the form. I believe you are on the right track though.
I have not seen "AS a HAVING a" used before could you explain what it does?
I was not able to figure out a workable solution by trying what I had mentioned previously. Logically it seem fairly simple, obviously I am missing some very important code.
Thanks again
Thank you for taking the time to post a response, your assistance is very much appreciated.
I gave it a test run and it did not give me any results for the running total, and it still listed all records in the table instead of what was in the date range on the form. I believe you are on the right track though.
I have not seen "AS a HAVING a" used before could you explain what it does?
I was not able to figure out a workable solution by trying what I had mentioned previously. Logically it seem fairly simple, obviously I am missing some very important code.
Thanks again
Right Track? Maybe...we'll see
I'm just aliasing the table name with a to make joins simple. you had something in there before..something like tblALLBCPIC1 or something. I just shortened it to a.
when you put your subquery into a SQL window by itself...will it return anything? -
SELECT Sum(nz(a.[ORDPCK],0)) FROM [tblALLBCPIC] AS a HAVING a.[DATE] < Date();
-
when you put your subquery into a SQL window by itself...will it return anything?
Yes it gives me one record with the total for all the records in the table.
Yes it gives me one record with the total for all the records in the table.
ok...so if you now want to only return dates between a certain range, we need to add the criteria for that there...
then once you get those results...We can link them in using the ID fields.
Are you enjoying learning about this stuff and how to "build" it all up? :o)
Are you enjoying learning about this stuff and how to "build" it all up? :o)
Mostly. My background is in web design, SQL seems a bit more difficult (and powerful) then what I am used to. It has been a steep learning curve for me.
So now I need to figure out how/where to add the date range criteria is what you are telling me? Sorry for not really "getting it", it is all so new and challenging for me.
Mostly. My background is in web design, SQL seems a bit more difficult (and powerful) then what I am used to. It has been a steep learning curve for me.
So now I need to figure out how/where to add the date range criteria is what you are telling me? Sorry for not really "getting it", it is all so new and challenging for me.
Around here (my work) it all runs together. Web Design, database, SQL, boredom!
and about the figuring out part....yep
You want to edit this SQL -
SELECT Sum(nz(a.[ORDPCK],0)) FROM [tblALLBCPIC] AS a HAVING a.[DATE] < Date();
-
replace the a.[DATE] < Date() with the criteria below. -
format(a.DATE,"mm/dd/yyyy")
-
Between
-
format([FORMS]![frmBCPIC]![date1], "mm/dd/yyyy") And
-
format([FORMS]![frmBCPIC]![date2], "mm/dd/yyyy");
-
Ok, it is definnatly giving me a different number now, probably to one I need.
Is there a way to display all of the records though, to create a running total not just a total?
Also in order to show the running total for the month to date (based on the same date range) would I need to modify the - format(a.DATE,"mm/dd/yyyy")
line of code?
Ok, it is definnatly giving me a different number now, probably to one I need.
Is there a way to display all of the records though, to create a running total not just a total?
Also in order to show the running total for the month to date (based on the same date range) would I need to modify the - format(a.DATE,"mm/dd/yyyy")
line of code?
Here is a working model for a running sum. -
SELECT M.ID, M.TDate, M.Feet, DSUM(""1"", ""M"", ""ID <= "" & M.ID & "") as Running_Count FROM M where [tDate] >= #1/1/2007# GROUP BY M.ID, MAR.TDate, M.Feet ORDER BY M.ID
-
let me know if you can look at yours side by side with this one...and figure out what's up?
J
Thanks again so much for your help and patience. I will check it out on Monday and post my results.
Have a great weekend! ( I know its only Thursday but no work for me tomorrow)
J
Here is a working model for a running sum. -
SELECT M.ID, M.TDate, M.Feet, DSUM(""1"", ""M"", ""ID <= "" & M.ID & "") as Running_Count FROM M where [tDate] >= #1/1/2007# GROUP BY M.ID, MAR.TDate, M.Feet ORDER BY M.ID
-
let me know if you can look at yours side by side with this one...and figure out what's up?
J
Ok, I took a look at your example and tried to rework it with my info, with no luck. Here is what I came up with based on your model. - SELECT tblALLBCPIC.ORDPCK, tblALLBCPIC.DATE, DSUM(""1"", ""tblALLBCPIC"", ""ORDPCK <= "" & tblALLBCPIC.ORDPCK & "") as Running_Count FROM tblALLBCPIC where [DATE] >= #1/1/2007# GROUP BY tblALLBCPIC.ORDPCK, tblALLBCPIC.DATE ORDER BY tblALLBCPIC.ORDPCK
I get a syntax error for the DSUM(""1""...... part, apparently I am missing an operator.
Once again if you have the time could you hold my hand and walk me through this please.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rajani |
last post by:
Hello,
I have a table(msaccess) with the structure...
job_code text 6
style text 10
qty number
fabrication text 65
ship_date date/time
|
by: fwells11 |
last post by:
Hi there. As you will see from my questions, I am an SQL newb. I
dabble but never get to spend enough time to get proficient so base any
feeedback on that basis please. This is all theoretical...
|
by: Peter Bailey |
last post by:
I have a query that creates a graph of bookings from the course start date
looking back 20 weeks based on a running sum.
I also have a query that counts the number of bookings before that 20 week...
|
by: Tony Williams |
last post by:
I have a database that hold s figures for each quarter. I want to create a
query whereby the user can ask for the running total of the data upto the
quarter they enter into a prompt. The database...
|
by: u473 |
last post by:
I am scratching my head with the required quotes and parentheses.
I started with an existing working Query with Running Total
by date.
Now I need to produce a running total by quarter day, so I...
|
by: Jerry LeVan |
last post by:
Hi,
I keep all of my financial data in Postgresql ( 7.4.2).
My "Check" register records deposits, withdrawals (as amount) , date,
category and other stuff.
The following sorta works...
...
|
by: Beacher |
last post by:
Hi all,
I'm having troubles with a report I've created. You make some
selections on a form which then sets a reports filter property and
opens the report, this works fine. One bigger problem...
|
by: mebrabham |
last post by:
Hello,
I am trying to create a running subtotal in a query and then graph the
running subtotal for each city group. The data looks like this in the
table (for illustration):
My City My...
|
by: klarae99 |
last post by:
I am working on an Inventory Database in Access 2003. I am working on a report that I could print when its time to file our State Sales Tax paperwork. The figures I need for this report are Total...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |