473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

simple yet beyond me

I have two columns:

Plantdate Totalpower
9/26/02 6217
10/31/02 5187
11/28/02 4246
12/26/02 4132
1/23/03 4313
2/21/03 4416
3/21/03 4355
4/24/03 5189
5/22/03 4237
6/26/03 5189
8/1/03 5339
8/28/03 4157
9/25/03 4270

I need to find the average use of power for each date by finding the
number of days between each date and dividing that into the power used
on that date. (dividing each power reading by 30 days is not accurate
enough). DateDiff doesn't work as there are not different date fields.
This is all between rows. I guess a procedure is the way to go. I
haven't programmed in Visual Basic. I would appreciate any pointers
in this area.

Or Is there a simple way of setting this up as a query?

Thank you

Trinity
Nov 12 '05 #1
3 2048
I think you're going to need some VBA code to do this in Access... there's
not really a "refer back to the previous record" in SQL. What are you going
to do with the result? If that is, display it in a report or form, I don't
think it's going to be very difficult.

Actually, it wouldn't be difficult in VBA code, but that would be useless
unless you were going to display or store the value.

Larry Linson
Microsof Access MVP
"trinity" <tr**********@lycos.com> wrote in message
news:f3**************************@posting.google.c om...
I have two columns:

Plantdate Totalpower
9/26/02 6217
10/31/02 5187
11/28/02 4246
12/26/02 4132
1/23/03 4313
2/21/03 4416
3/21/03 4355
4/24/03 5189
5/22/03 4237
6/26/03 5189
8/1/03 5339
8/28/03 4157
9/25/03 4270

I need to find the average use of power for each date by finding the
number of days between each date and dividing that into the power used
on that date. (dividing each power reading by 30 days is not accurate
enough). DateDiff doesn't work as there are not different date fields.
This is all between rows. I guess a procedure is the way to go. I
haven't programmed in Visual Basic. I would appreciate any pointers
in this area.

Or Is there a simple way of setting this up as a query?

Thank you

Trinity

Nov 12 '05 #2
DFS
trinity,

Here's an all-SQL solution involving 3 queries - no VBA coding necessary:

Query1 (note: self-join Table to itself)
SELECT Table.PlantDate, Table_1.PlantDate AS PrevPlantDate,
Table.TotalPower, Table_1.TotalPower AS PrevPower
FROM [Table] INNER JOIN [Table] AS Table_1 ON Table.PlantDate >
Table_1.PlantDate;

Query2: for each date, get the minimum other date
SELECT PrevPlantDate, Min(PlantDate) AS MinOfPlantDate
FROM Query1
GROUP BY PrevPlantDate;

Query3: join query2 to query1
SELECT Query1.*
FROM Query2 INNER JOIN Query1 ON (Query1.PrevPlantDate =
Query2.PrevPlantDate) AND (Query2.MinOfPlantDate = Query1.PlantDate);

Query 3 will give you the data you want. Note: I did it kind of quickly, so
I might have mislabeled some things, but it should be right.


"trinity" <tr**********@lycos.com> wrote in message
news:f3**************************@posting.google.c om...
I have two columns:

Plantdate Totalpower
9/26/02 6217
10/31/02 5187
11/28/02 4246
12/26/02 4132
1/23/03 4313
2/21/03 4416
3/21/03 4355
4/24/03 5189
5/22/03 4237
6/26/03 5189
8/1/03 5339
8/28/03 4157
9/25/03 4270

I need to find the average use of power for each date by finding the
number of days between each date and dividing that into the power used
on that date. (dividing each power reading by 30 days is not accurate
enough). DateDiff doesn't work as there are not different date fields.
This is all between rows. I guess a procedure is the way to go. I
haven't programmed in Visual Basic. I would appreciate any pointers
in this area.

Or Is there a simple way of setting this up as a query?

Thank you

Trinity

Nov 12 '05 #3
DFS
I didn't read your question thoroughly. My solution will work, but you need
to add a calculated field to the last query.

So Query3 becomes:

SELECT Query1.*, TotalPower/(PlantDate - PrevPlantDate) as CalcPower
FROM Query2 INNER JOIN Query1 ON (Query1.PrevPlantDate =
Query2.PrevPlantDate) AND (Query2.MinOfPlantDate = Query1.PlantDate);

"DFS" <no****@nospam.com> wrote in message
news:10*************@corp.supernews.com...
trinity,

Here's an all-SQL solution involving 3 queries - no VBA coding necessary:

Query1 (note: self-join Table to itself)
SELECT Table.PlantDate, Table_1.PlantDate AS PrevPlantDate,
Table.TotalPower, Table_1.TotalPower AS PrevPower
FROM [Table] INNER JOIN [Table] AS Table_1 ON Table.PlantDate >
Table_1.PlantDate;

Query2: for each date, get the minimum other date
SELECT PrevPlantDate, Min(PlantDate) AS MinOfPlantDate
FROM Query1
GROUP BY PrevPlantDate;

Query3: join query2 to query1
SELECT Query1.*
FROM Query2 INNER JOIN Query1 ON (Query1.PrevPlantDate =
Query2.PrevPlantDate) AND (Query2.MinOfPlantDate = Query1.PlantDate);

Query 3 will give you the data you want. Note: I did it kind of quickly, so I might have mislabeled some things, but it should be right.


"trinity" <tr**********@lycos.com> wrote in message
news:f3**************************@posting.google.c om...
I have two columns:

Plantdate Totalpower
9/26/02 6217
10/31/02 5187
11/28/02 4246
12/26/02 4132
1/23/03 4313
2/21/03 4416
3/21/03 4355
4/24/03 5189
5/22/03 4237
6/26/03 5189
8/1/03 5339
8/28/03 4157
9/25/03 4270

I need to find the average use of power for each date by finding the
number of days between each date and dividing that into the power used
on that date. (dividing each power reading by 30 days is not accurate
enough). DateDiff doesn't work as there are not different date fields.
This is all between rows. I guess a procedure is the way to go. I
haven't programmed in Visual Basic. I would appreciate any pointers
in this area.

Or Is there a simple way of setting this up as a query?

Thank you

Trinity


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: gaudetteje | last post by:
I've been searching high and low for a way to simply convert a small XML configuration file to Python data structures. I came across gnosis XML tools, but need a built-in option for doing...
18
by: Alan Little | last post by:
Viewed in IE, this page is exactly what I'm trying to do: http://www.holotech.net/links/ Header, two fixed-width columns, and a footer. However, in NS and Opera, the second column slides to...
2
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select...
10
by: S | last post by:
Hello I have a (fairly) simple layout, part of which you folks so kindly helped me with already (thank you all). This layout contains: - A header area (100% width across top) - A nav area...
4
by: Timmah1980 | last post by:
I'm sure this is a simple enough fix for someone out there, but I'm afraid it's beyond me! I'm putting together this simple menu for a client: http://www.timkeay.co.uk/mpc2/index.htm It...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.