Bee said:Hi,
Is it possible to add a calcualted field to a query that already uses 'sum'?
I want to take the value returned by sum and add the value of another field to it.
Any help will be very much appreciated.
B
Yes, what you mentioned is what I wanted to do. I will try second query.Brianwarnock said:The aggregate functions work across the recordset, how can you add another field to it all the records will have been read. Not sure I understand what you are trying to do, if you are trying to say sum field1 for the selected records, then add field2 to produce field3 for each record then do it as a second query.
Brian
I have a sum([X]) in a query where X is from one table and I want to add the value of a field from another table to the sum. The value I wanted to add though is not a summed value. So in theory, it will be pretty much what you said: Sum([X]) + 6 where 6 is the value of the field from the other table.The_Doc_Man said:There are a couple of possible ways to interpret this.
A query can certainly contain a box that says Sum([X]) + Sum([Y]) where X and Y are two fields in the underlying table.
A query can certainly contain a box that says Sum([X]) + 6.
However, mathematically, if X and Y are two fields in two different tables that participate in an inner join, you get something a little more complex. There is a cardinality constant associated with such cases, showing how many times each JOIN occurred for the base table. This is in line with basic algebra rules for summations. Heavens forfend that the JOIN ever becomes an OUTER JOIN, because then you would NEVER know what you really have.
Oh sorry, i thought it was the same. So, will go for 2 queries.Brianwarnock said:I'm sorry but Sum([X]) + [FieldName] is not at all the same as Sum([X]) + 6, as I said earlier you need 2 queries, the second using the result of the aggregate query.
Brian
Bee said:Oh sorry, i thought it was the same. So, will go for 2 queries.
Instead of using 2queries, how about adding that last value [FieldName] using VB? Or is it a bad practice?
Not sure I understand what you are trying to do, if you are trying to say sum field1 for the selected records, then add field2 to produce field3 for each record