PC Review


Reply
Thread Tools Rate Thread

Calculate annual differences and changes through time

 
 
=?Utf-8?B?Y3Nm?=
Guest
Posts: n/a
 
      26th Jan 2005
Would like to display elevation changes for instruments that are surveyed on
an annual basis. Also, would like to display total change through time.

InstID Survey Date Elevation
4 05/09/2001 176.245
4 07/11/2002 176.166
4 04/15/2003 176.170

I modified an SQL statement from a previous reply by Jamie Collins on
10/28/2004 as follows (table name is Test):

SELECT T2.InstID, T2.SurveyDate AS Expr1, [T2].[Elevation]-IIf((SELECT
T1.Elevation FROM Test T1 WHERE T1.SurveyDate = (SELECT MAX(SurveyDate) FROM
Test WHERE SurveyDate<T2.SurveyDate)) Is Null,0,(SELECT T1.Elevation FROM
Test T1 WHERE T1.SurveyDate = (SELECT MAX(SurveyDate) FROM
Test WHERE SurveyDate<T2.SurveyDate))) AS new_amount
FROM Test AS T2
ORDER BY T2.SurveyDate;

Results
InstID Survey Date new_amount
4 05/09/2001 176.245
4 07/11/2002 -0.079
4 04/15/2003 0.004

This is very close to what I would like to accomplish. How do I modify the
SQL to calculate the new_amount for the first Survey Date to be NULL or 0 so
that I may sum the new_amount for the period of record?

Thanks in advance for any assistance,
Chris
 
Reply With Quote
 
 
 
 
Ken Snell [MVP]
Guest
Posts: n/a
 
      26th Jan 2005
Try this:

SELECT T2.InstID, T2.SurveyDate AS Expr1, [T2].[Elevation]-IIf((SELECT
T1.Elevation FROM Test T1 WHERE T1.SurveyDate = (SELECT MAX(SurveyDate) FROM
Test WHERE SurveyDate<T2.SurveyDate)) Is Null,0,(SELECT T1.Elevation FROM
Test T1 WHERE T1.SurveyDate = Nz((SELECT MAX(SurveyDate) FROM
Test WHERE SurveyDate<T2.SurveyDate),0))) AS new_amount
FROM Test AS T2
ORDER BY T2.SurveyDate;


--

Ken Snell
<MS ACCESS MVP>

"csf" <(E-Mail Removed)> wrote in message
news:717AE0F6-6EC0-4975-AFDF-(E-Mail Removed)...
> Would like to display elevation changes for instruments that are surveyed
> on
> an annual basis. Also, would like to display total change through time.
>
> InstID Survey Date Elevation
> 4 05/09/2001 176.245
> 4 07/11/2002 176.166
> 4 04/15/2003 176.170
>
> I modified an SQL statement from a previous reply by Jamie Collins on
> 10/28/2004 as follows (table name is Test):
>
> SELECT T2.InstID, T2.SurveyDate AS Expr1, [T2].[Elevation]-IIf((SELECT
> T1.Elevation FROM Test T1 WHERE T1.SurveyDate = (SELECT MAX(SurveyDate)
> FROM
> Test WHERE SurveyDate<T2.SurveyDate)) Is Null,0,(SELECT T1.Elevation FROM
> Test T1 WHERE T1.SurveyDate = (SELECT MAX(SurveyDate) FROM
> Test WHERE SurveyDate<T2.SurveyDate))) AS new_amount
> FROM Test AS T2
> ORDER BY T2.SurveyDate;
>
> Results
> InstID Survey Date new_amount
> 4 05/09/2001 176.245
> 4 07/11/2002 -0.079
> 4 04/15/2003 0.004
>
> This is very close to what I would like to accomplish. How do I modify
> the
> SQL to calculate the new_amount for the first Survey Date to be NULL or 0
> so
> that I may sum the new_amount for the period of record?
>
> Thanks in advance for any assistance,
> Chris



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I use excel to calculate average annual ROI... =?Utf-8?B?cGl0dHNidXJnY2F0?= Microsoft Excel Misc 4 20th May 2007 05:58 AM
How do I calculate IRR using monthly cash flows, not annual? =?Utf-8?B?TWlrZSBLbm94dmlsbGU=?= Microsoft Excel Worksheet Functions 2 26th Oct 2005 03:14 PM
How to calculate Date & Time differences robs Microsoft Excel Discussion 8 6th Oct 2005 02:53 AM
How to calculate Date & Time differences robs Microsoft Excel Worksheet Functions 2 4th Oct 2005 04:22 PM
how do I calculate the annual interest when I know the compound =?Utf-8?B?ZGF3bjI1MTE=?= Microsoft Excel Worksheet Functions 4 20th Jul 2005 06:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.