Refer to previous calculated field

captain1974

Registered User.
Local time
Tomorrow, 06:38
Joined
Jan 15, 2007
Messages
43
Access 2003.
I was just wondering if there was any way to refer to a calculated field in the same query.
For example if the first calculated field was - Total: ([Quantity])*([Price]), could you add another calculated field - Inc Tax: ([Total])*1.175.
At present I am having to type the whole formula in the calculated field again which seems to work for some queries, but not for others, no matter how I fiddle about with the syntax. The other way is to create another query and refer to my previous query. Both these methods seem extremely cumbersome and I was wondering if I have missed something with referring to a prior calculated field.
The query above is just an example, my query formulas are actually fairly long and for editing purposes it can be difficult to correct them.
 
Nothing wrong with

Total: ([Quantity]*[Price]) and IncTax: (1.175*[Quantity]*[Price])
 
The_Doc_Man said:
Nothing wrong with

Total: ([Quantity]*[Price]) and IncTax: (1.175*[Quantity]*[Price])

Ok, I'll be more specific. The above example is fairly simple, but when you have queries more like:
Yield/Ha: (Format(Avg([BunchCount]*10000/([RowWidth]*[VineSpacing])*([BunchWeight]/1000000)*([BlockPercent])*(1/[Half or Whole Vines])*([BlockPercent])*(1-[Missing Vine])*(1-[HarvesterLoss])*(1-[BirdLoss])*(1-[ThinningLoss])),"Standard"))
And a number of them running in sequence referring to the bulk of the last calculation it gets a bit of a headache for editing purposes. I guess I was just wondering if I was doing something wrong with syntax, if it can't be done then so be it....
 
what you have should work OK.
just did a quick test with
SELECT oee.ID, oee.TotalProduction, oee.PlannedProduction, [PlannedProduction]-[TotalProduction] AS total, oee.GoodProduction, [total]+[goodproduction] AS Test
FROM oee;

which ran Ok

Peter
 
For anyone else looking, I had the same problem, I removed the fields from the query that referred to previously calculated fields, ran the query, put the fields back in and they worked. Seems the query needed to run for the first time to recognise the calculated filed's names before it would let you refer to them.

HTH
 

Users who are viewing this thread

Back
Top Bottom