Can a calculation in a query use information from a second calculation in
the
Yes, I have many very complex queries like that.
When you include a calculation like that, it is calculated over and
over. At least one re-calculation for everytime the value is used,
and possibly more.
If you have a line like
c1: ElapsedTimeString([Start time],[Stop time])
v1/ [C1]
v2/ [C1]
v3/ [C1]
v3/ [C1]
where [start time] and [stop time] are field in the record,
then C1 is recalculated (at least) once every time it is used.
So you don't gain any speed by using the alias c1 for the
calculation, it just makes the query easier to read.
On the other hand, there is no possibility that the query is
failing because 'calculation1' has not been calculated yet:
it is calculated in every field where it is used.
So it may be that your query is failing because [start time] and
[stop time] are the same, or because you have a problem in
your calculation function, or because the return value of the
function is not a number.
Doing divisions like that, I always guard the division. Perhaps
with something like this:
IIF(val(calculation1)<>0,[volume]/calculation1,Null)
When you have more complex calculations that have internal
database lookups, it is a good idea to check the function
parameters inside the function, and use a saved value if the
parameters have not changed. If that was a very slow function,
using a saved value would automatically make your query
twice as fast, even if the value was just used twice! In practice,
a User Defined Function like that is called even more often
than once every time it is used, so the speed of a slow function
is even more critical.
(david)
Katherine said:
Can a calculation in a query use information from a second calculation in the
same query?
I am trying to calculate an average rate. I have one calculation that gives
me the time, but when I try to include that field in a [volume] / [time]
calculation, it just shows up as #ERROR. How should I write the calculations
to make this work?
This is what they look like now:
Calculation 1: ElapsedTimeString([Start time],[Stop time]) (I got the
calculation from somewhere on this site and put it in a module)
Calculation 2: [Volume] / [Calculation 1]
Thanks,
Katherine