Sometimes you need to extract data from your database and calculate it. Aggregate functions (for example, sums, counts, and averages) enable you to calculate and summarize data in your queries. This topic explains what an aggregate function is and shows you how to apply this type of function to your data.
What Is an Aggregate Function?
Adding an Aggregate Function to a Column's Data
Removing an Aggregate Function from a Column's Data
Examples of Queries Using Aggregate Functions
To aggregate means to put together or combine. An aggregate function, therefore, performs a calculation on the values in a column and returns a single (combined) value, such as a count or an average. Examples of using this type of function are as follows:
● Finding the sum (total) values in a column. Example: the total amount contributed to a specific fund.
● Obtaining a count of a set of records. Example: the total number of 18-year-old members in an organization.
● Determining the average value in a column. Example: the average dollar amount of pledges made to a specific fund.
● Finding the lowest value in a column. Example: the lowest contribution amount made to a specific fund.
● Finding the highest value in a column. Example: the oldest member in your organization.
In each example, all you want is a summary of the column's data—not the column's actual data. Therefore, the query result is always equal to 1.
Five aggregate functions are available in ParishSOFT IQ. These functions are located on a special Functions menu ():
The following table lists and describes the aggregate functions.
Aggregate Function |
Description |
Sum |
Adds all of the values in a column together and returns the sum of the numeric values. |
Count |
Counts the number of values in a column that meet the specified condition and returns a single integer value that represents the total number counted. |
Average |
Averages the values in a numeric column and returns the average value. |
Minimum |
Finds the lowest (or smallest) value in a column. |
Maximum |
Returns the highest (or largest) value in a column. |
You can assign an aggregate function to any column in the Results Column panel. To assign a function to a column, do the following:
Position your cursor on top of the column you want to assign the aggregate function to.
Drag your cursor to the right until you see this icon, and then click it: to display the Functions menu:
Select the desired function.
The function is added to the column name and title to let you know that it will be applied when you run the query. For example:
To remove an aggregate function from a column, drag your cursor to the right of the column until you see this icon, and then click it: .
The function is removed from the column name and title to let you know that it is no longer being applied.
This section gives you examples of queries using these aggregate functions:
● Count
● Average
● Maximum
The most commonly used aggregate function is the Count function. Following is an example of how you might use this function.
Question:
How many registered families live in the 48108 zip code?
Analysis:
For this question, you are looking for a single value: the total number of registered family records. You can obtain the answer by applying the Count aggregate function to the Families > is Registered column. Because you also want to limit the records retrieved to those of registered families in the 48108 zip code are, you need to apply a condition to this column to specify the zip code: Families > Addresses > Home PostalCode.
Query:
The following procedure shows you how to set up a query to answer the question.
In the Column Picker panel, select Families > is registered.
The Count function is now applied to the column.
Families. Addresses.Home PostalCode is equal to 48108.
The query adds up the number of records in the is Registered column returns a single value. As shown in the example below, the query determines that the number of registered families in the 48108 zip code area is 6480:
The Average function is used to find the average value of a certain column for a selected group of records. The column's value must be numeric for the Average function to work.
Question:
What is the average amount pledged to the Building Fund Campaign fund?
Analysis:
For this question, you are looking for a single numeric value: an average of the dollar amounts in the Pledges > Pledge Total Amount column. The query must add up the values in this column and then calculate the average dollar amount. The query also applies a condition to Funds > Description column to retrieve records for the Building Campaign Fund only.
Query:
The following procedure shows you how to set up the query to answer this question.
The Average function is applied to the Pledges Total column.
The query calculates the average value in the Pledges Total column and returns the single result. As shown below, the query determines that the average amount pledged to the Building Fund Campaign fund is $1675.00:
The Maximum function is used to find the highest value in a certain column for a selected group of records.
Question
What is the age of the oldest member in our organization?
Analysis
For this question, you are looking for a single result (age of the oldest member), which you can obtain by applying the Maximum aggregate function to the Members > Age column.
Query
The following procedure shows you how to set up the query to answer this question.
The Maximum function is now applied to the column.
The query calculates the maximum value in the Age column and returns the single result. As shown in the example below, the query determines that the oldest member in the organization is 118 years old: