G
Guest
In the drop-down list in the Totals row in a Query grid, what does
"expression" refer to? How do you use it?
"expression" refer to? How do you use it?
Allen Browne said:A totals query aggregates data.
For each field, you specify how to aggregate that column's data, e.g.:
- Group By means to return each value;
- Sum means add up all values for the grouped by fields.
Expression means: don't aggregate on this field, just include a column
with this value. For example, if you type into the Field row:
Expr1: 99
and choose Expression, you get a 99 on every row of the query.
Since the expression is tacked on after aggregation, it can refer to other
fields that are in the query results. Any Group By field is in the
results, so if you group by Surname and FirstName, you can use an
expression such as:
Expr1: [FirstName] & " " & [Surname]
If you have a field called Amount that you Sum, Access will alias the
column as SumOfAmount. You can therefore refer to that in your Expression.
For example, to calculate 8% sales tax on the amount:
Expr1: [SumOfAmount] * 0.08
If you look at the SQL statement, these expressions are fields in the
SELECT clause that are not in the GROUP BY clause.
Joshcat99 said:In the drop-down list in the Totals row in a Query grid, what does
"expression" refer to? How do you use it?
Expressions are fields in the SELECT clause
that are not in the GROUP BY clause,
and have no aggregation (such as First or Sum or Count.)
Allen said:The last sentence skipped an important point:
Expressions are fields in the SELECT clause
that are not in the GROUP BY clause,
and have no aggregation (such as First or Sum or Count.)
Allen Browne said:A totals query aggregates data.
For each field, you specify how to aggregate that column's data, e.g.:
- Group By means to return each value;
- Sum means add up all values for the grouped by fields.
Expression means: don't aggregate on this field, just include a column
with this value. For example, if you type into the Field row:
Expr1: 99
and choose Expression, you get a 99 on every row of the query.
Since the expression is tacked on after aggregation, it can refer to other
fields that are in the query results. Any Group By field is in the
results, so if you group by Surname and FirstName, you can use an
expression such as:
Expr1: [FirstName] & " " & [Surname]
If you have a field called Amount that you Sum, Access will alias the
column as SumOfAmount. You can therefore refer to that in your Expression.
For example, to calculate 8% sales tax on the amount:
Expr1: [SumOfAmount] * 0.08
If you look at the SQL statement, these expressions are fields in the
SELECT clause that are not in the GROUP BY clause.
Joshcat99 said:In the drop-down list in the Totals row in a Query grid, what does
"expression" refer to? How do you use it?