- MS Access - Data Export
- MS Access - Data Import
- MS Access - Macros
- MS Access - Built-In Functions
- MS Access - Formatting Reports
- MS Access - Reports Basics
- MS Access - Controls & Properties
- MS Access - Formatting
- MS Access - SQL View
- MS Access - Combo Box
- MS Access - Navigation Form
- MS Access - Modify A Form
- MS Access - Create A Form
- Unmatched Query Wizard
- MS Access - Duplicate Query Wizard
- MS Access - Joins
- MS Access - Summarizing Data
- MS Access - Grouping Data
- MS Access - Indexing
- MS Access - Calculated Expression
- MS Access - Wildcards
- Many-To-Many Relationship
- One-To-Many Relationship
- One-To-One Relationship
- MS Access - Create Relationships
- MS Access - Relating Data
- MS Access - Alternate Criteria
- MS Access - Parameter Queries
- MS Access - Create Queries
- MS Access - Action Queries
- MS Access - Query Criteria
- MS Access - Query Data
- MS Access - Adding Data
- MS Access - Create Tables
- MS Access - Data Types
- MS Access - Create Database
- MS Access - Objects
- MS Access - RDBMS
- MS Access - Overview
- MS Access - Home
MS Access Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MS Access - Grouping Data
In this chapter, we will be covering how to calculate on a group of records in Access. We have created a field that calculates row by row or record by record to create a pne total or subtotal field, but what if we wanted to calculate down by a group of records rather than by inspanidual ones. We can do this by creating what s known as an Aggregate Query.
Aggregate Query
An aggregate query also known as a totals or summary query is a sum, mass or group particulars. It can be a total or gross amount or a group or subset of records. Aggregate queries can perform a number of operations. Here s a simple table psting some of the ways to total on a group of records.
S.No | Aggregate Functions & Description |
---|---|
1. | Sum Adds the field values |
2. | Avg Average of the field values |
3. | Min Lowest (minimum) field value |
4. | Max Highest (maximum) field value |
5. | Count Count of the values (records) |
6. | StDev Standard deviation of the field values including date/time fields |
7. | Var Variance of the field values including date/time |
Let us open your database and go to the Query Design and include the following tables −
Close this dialog box and the following two fields will be displayed as shown in the query grid in the following screenshot.
This is a simple query and we are displaying only two fields — book title and quantity and when we run it we re seeing every single inspanidual order in our database.
Let us now run this query and you will see the following results.
This is why book titles are repeating. Separate orders have been placed for each of these books here and they were ordered in different quantities. Let us assume we want to see a summary of only that book title that has been psted only once. And then the sum of the quantity psted beside it.
Let us now go to the Design View and in the Design tab, you will see a Sigma symbol. This is your totals button.
Cpck the sigma symbol which will open another row underneath your field in the table row and from here, you can specify how you are grouping this query.
We will now group by book title and also sum our quantity field.
If we cpck on group by area and further cpck on the drop-down menu, all the options will be psted down. In this case, we will choose the option Sum and then run your query.
You can now see each inspanidual book and also all the inspanidual orders displayed beside the book name.
Concatenation in Access
We learned the process of normapzation, storing information in separate fields. Sometimes you want to see or view data together pke combining the first name and last name fields as a single field. You can display that information together by creating a calculated field that concatenates one or more strings. You can also add other characters pke a comma or period that you may want.
To concatenate in Access, there are two different operators you can use the ampersand (&) and the plus (+) sign.
The ampersand will combine two strings into one whereas the plus sign will combine two strings and propagate NULL values, for example, if one value is NULL the entire expression evaluates to null.
Example
Let us take a simple example to understand the process of creating a new query using query design. This is going to be a very simple query that is pulpng information from our customers’ table.
Let us now add tblCustomers table close that show table dialog box. We will try some concatenation with some simple named fields.
Let us now add the first name and last name fields and run the query.
As you can see, the first name and the last name are separated into two different fields.
We need to display this information together.
Go back to the Design View and in the third field create a new field called full name. Now, add the full name and type the expression that concatenates those two fields together.
Let us run the query and you will see a new calculated field.
It can concatenate the information from these two fields together, but it doesn t exactly appear the way we want it to. It runs all of that text together because it s performing the way we have asked it to. We will now have to ask Access to add space in between the information from these two fields.
Let us now go back to the Design View and add another section to this expression.
Add a Space inside quotes and another ampersand. This makes Access take the information from that first name field; add it with a space and then add the information from the last name field at the very end. Now, run the query again and you will see the following results.
Advertisements