Aggregation only
Strict aggregation-only use is most similar to the SQL GROUP BY statement, where it arranges the query results into groups of rows, usually to perform one or more aggregations on each group. Nearly all widgets in SuperOffice Dashboards use this form of aggregation to display results. Using the archive providerappointmentdynamicselection, construct a query that will count all activities for the current user for the past month and group them by type.
Use the Count function to count each unique appointment ID, and use the HideDetail modifier to remove the column from the detail rows. Then use the GroupBy function to divide the query results into activity types. Use the Footer modifier to output a footer row that contains the count and type columns for each group. Also, append the HideDetails modifier to not return any detail rows; just the footer rows.
Query output
Row type
Similar to reports, combined aggregation results useGroupBy functions together with other columns, both aggregate and non-aggregate, to display Header, Footer, and Detail rows.
For example, a new group of rows is created every time a GroupBy column value changes, dividing the results into one or more Header - Details - Footer rows. Modifiers are used to control where aggregation columns reside and become accessible.
The RowType property of a row determines if the output is a normal detail row, header row, footer row, or grandtotal row.
To demonstrate the concepts, create a query that uses the person archive provider and set the desired columns to include the
firstName, middleName, lastName, and rank, then set the restriction to where the contactId equals 24. Next, create three aggregate columns that do the following:
- Sum the rank column for display in details.
- Count all of the occurrences of
firstNamefor display in details. - Group the results by
middleName, and make this column available in both the header and footer, but hide in detail rows.
Sample data - company name: Superoso, 5 employees
Using the sample data, the results are divided into two distinct groups. The first group contains all persons with the middle name Ray and the second group contains all people with the middle name Sue.
Every time the middle name changes, the results will create and output a new band of header, detail, and footer rows. According to the specification, two of the aggregate columns are available in the detail rows, but the
GroupBy column is only available in the header and footer rows of each band.
Query Output
GrandTotal
If theprovider.GetRows method included the GrandTotal option, the last row in the results includes the GrandTotal row type. Notice how the Sum and CountAll functions appear and display the total results. All aggregate columns, except GroupBy, are included and available in the GrandTotal row.
Multiple-level GroupBy
It’s easy to specify an additional group level with the integer modifier. Building on the last example, create a query that sets the desired columns to include thefirstName, then set the restriction to where the contactId equals 24. Next, create these five aggregate columns:
- Count all of the occurrences of
firstNamefor display in details. - Count the unique occurrences of
middleNamefor display in details. - Sum the rank column for display in details.
- Group the first level of results by
middleName, and make the column available in both the header and footer, but hide in detail rows. - Group the second level of results by lastName, and make the column available in the details row, as well as both the header and footer.
Query output
The output includes two first-level groups; one for each of the two different middle names. The first band is grouped by
middleName and contains two people with the middle name Ray. Because both of these people share the same last name, there are no nested levels grouped by lastName. The second group contains three people with the same second name. However, only two share the same last name and so there becomes two nested groups; one for lastName Doe and one for last name Smith.