can a calculated field look at the record before the current record (1 Viewer)

Ruzz2k

Registered User.
Local time
Today, 00:36
Joined
Apr 28, 2012
Messages
102
Hi I have a query to bring in values, I need to select 2 rows of data but the criteria is as such:

x= starting value on form
now the row of data must match the following criteria
previous row to current row(ref temp)<=x And Current row(ref temp)>x
next row to current row(ref temp)>=x And Current row(ref temp)<x

I have dealt with SQL before but have no idea how to do the above.

The isolated 2 rows of data will then go into unbound boxes on a form from which I will do intercept and gradient calculations.

Thanks for your help
 

plog

Banishment Pending
Local time
Yesterday, 18:36
Joined
May 11, 2011
Messages
11,653
As with anything complex, the answer is maybe. First you have to understand that order only exists in data when you tell it to exist. There is inherently no 'next', 'previous', 'first' nor 'last' record with a pile of data. Order only exists when you tell it specifically how to exist.

So, how does order exist in your data? Is there a date field? A numerical field? Once you have that, then you will be able to do what you want. Post the field names of your query, identify the field to order your data by, post some sample data and finally what you want the final output to be based on that sample data.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 00:36
Joined
Sep 12, 2006
Messages
15,660
because of considerations such as those plog just mentioned - it is wirth thinking carefully about your data, and what you are trying to achieve. The concept of order within a database is somewhat nebulous.

- so do you really need tro refer to the previous item. or would a total of all the items you have give you what you want. if you do need the previous item, then consider storing the value of the previous item in the current item - so this is just a one-time process.

if you do that though, you need to be conscious of problems if data gets amended subsequently - as it will then affect other items.

note that in a report, it is not a problem - as a report is inherently structured, and there clearly is a previous item on a report. it's just that in forms and queries, the "previous" item is arbitrary - it can change simply by resorting the data.
 

Ruzz2k

Registered User.
Local time
Today, 00:36
Joined
Apr 28, 2012
Messages
102
hi Guys thanks, I have come to present more data for my problem.

Table uploaded
So in the primary instance I will use a query linked to what is selected as a reference probe on the main form.

So from the query I maybe need to convert the query to an array as I need the following to happen ultimately:
I will have a temperature on the main form in a text box which has been > the ref value on the form AND the ref value for the row above the one we are looking at is <= the ref value on the form. Then these values are selected.
finally these values are then used to do y=mx+c to calculate gradient and slope and then other values.
problem is we are essentially picking the two sets of value that my calculated value falls between so I can essentially calculate the error for my calculated value that sits between the two ref values.

Thanks happy to provide any more data a this is my current stumbling block

Thanks.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    52.4 KB · Views: 99
Last edited:

RainLover

VIP From a land downunder
Local time
Today, 09:36
Joined
Jan 5, 2009
Messages
5,041
I would suggest that you build your query in the query grid.

This way you can introduce one criteria at a time and test as you go.
 

Users who are viewing this thread

Top Bottom