Calculating Totals in Access QueriesAn often-overlooked feature of the ordinary select query is its ability to calculate totals. Whilst the crosstab query is useful for analysing complex data, it needs several fields to work with. Supposing the data you wish to analyse is contained in just two fields? The answer is to create a select query and make use of the totals option.Totals can do more than just add up too! Here's how it works… We have a table containing a mass of sales data. The records are arranged in no particular order, and there are several fields containing information about each individual sale… If we wanted, we could do a sophisticated analysis of this data with a crosstab query, but to begin with all we want to know is "What are the total sales for each person?" All the data we need is contained in just two fields, Salesperson and Sales, and a crosstab query needs at least three fields to work with. No problem! We're going to use Totals. Adding Totals to a QueryThe first step is to create a query selecting the fields we are interested in. Running the query at this stage simply presents with a list of data. In this case Salespeople and numbers representing individual Sales. But we need to analyse this data…
Refining the QueryYou can still add criteria to the query definition if you wish. Here, criteria have been added to the Salesperson field to select records for specific salespeople…Grouping by Several FieldsYou can group my as many fields as you wish, providing the chosen fields contain suitable data.
Using Additional CriteriaIt may be that you want to specify certain criteria referring to another field, but you don't want to group by that field or calculate its data. To do this, select the Where option in the Totals row. This lets you add criteria to the criteria row of that field to further refine your query. When you do this Access unchecks the Show box for that field. If you want to see the new field in the result of your query, you must add to the QBE grid a second time (with Grouped By selected in its Totals row). Construct the query like this…The Region field has been added to the QBE grid twice, first using the Where option to specify criteria, and again using Group By to let the result be shown.
Note: Because what you see when you run your query using Totals is a summary of your data, it doesn't behave like a normal dynaset. Changes made to the data here are not reflected in the original data. | ||||||||
| ^ top | ||||||||
Tuesday, 15 March 2011
sales by sum
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment