Surv
asked on
Calculate using a field in current & prev record
Hi,
Is there an easy way to calculate the difference (movement) between a field value in my current record and the value of the same field in a either the previous or the next record. This should be done with all the records in the table (like a calculated field).
i.e.
field calculated field
record 12 1090
record 13 1096 6(movement 13-12)
Thanks
Is there an easy way to calculate the difference (movement) between a field value in my current record and the value of the same field in a either the previous or the next record. This should be done with all the records in the table (like a calculated field).
i.e.
field calculated field
record 12 1090
record 13 1096 6(movement 13-12)
Thanks
ASKER
Adjusted points from 40 to 100
ASKER
Edited text of question.
What database server are you using?
Alex
Alex
ASKER
Hi Simonet,
No server, just a small paradox 7 table, stand alone pc.
Is my question clear ? It almost seems as if I wrote it a bit confusing.
I have a field which stores a value. All I would like to do is create an extra field or whatever to display the movements of the difference between this field's values between records It should display this "movement" field in a dbgrid preferably.
I am quite new to delphi / Paradox etc.
If you know FileExpress for example, you could enter a function which will calculate the movement between fields in different records by accessing the next or previous records without moving the focus to them i.e.
field_z := field_3 - field_3(prev)
Can you possibly help me to an answer.
Cheers
No server, just a small paradox 7 table, stand alone pc.
Is my question clear ? It almost seems as if I wrote it a bit confusing.
I have a field which stores a value. All I would like to do is create an extra field or whatever to display the movements of the difference between this field's values between records It should display this "movement" field in a dbgrid preferably.
I am quite new to delphi / Paradox etc.
If you know FileExpress for example, you could enter a function which will calculate the movement between fields in different records by accessing the next or previous records without moving the focus to them i.e.
field_z := field_3 - field_3(prev)
Can you possibly help me to an answer.
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Comment accepted as answer
ASKER
Thanks Ivan,
I can use it, it works ok.
cheers - Surv
I can use it, it works ok.
cheers - Surv
You well come.
Ivan
Ivan
function Difference(Direction: string): integer;
var
Current: integer;
begin
Current := table.fieldByname('calcula
if Direction = 'Next' then
begin
table.Next;
result := table.fieldbyname('calcula
table.previous;
end
else if Direction = 'Previous' then
begin
table.previous;
result := current - table.fieldbyname('calcula
table.next;
end
else
result := 0;
end;
assuming your table is called table etc.
Hope that helps,
Dave.