Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
Overview
Aggregate functions, often grouped by other attributes, give totals, max, min, average values etc. for each key value they are provided. For example, you can sum the amount of all the lines on an invoice based on an invoice number.
Aggregate functions are available to use on stream views and pipes.
Aggregating with a Pipe.
Pipe aggregation is useful for simple aggregations. To configure a pipe for aggregation
- Click on a pipe to open its properties.
- In the Aggregate Attributes section, click the plus button to add a new attribute.
- Complete the details:
- A Function: select the function you wish to perform e.g. sum. A complete list is provided in the function section at the end of this page.
- Attribute: select the attribute you wish to perform the function on.
- Name: name your new attribute.
- Aggregation on a pipe takes place across all groups of data. Therefore you can define which attribute(s) you wish to group on by adding these to sort/group, or if no grouping is provided aggregation takes place across all records.
- Click
to save your changes.Insert excerpt _finish _finish nopanel true - The table connected to the end of the pipe can now access your attribute using its name.
Info |
---|
You will not be able to refer to any attributes in the source table for which there is no grouping or aggregate attribute. |
Aggregating with a Table
- Click on the pipe connecting to an Aggregate Table to open its properties.
- Aggregation takes place across all groups of data. Therefore you can define which attribute(s) you wish to group on by adding these to Sort/Group, or if no grouping is provided aggregation takes place across all records.
- Click
to save your changes.Insert excerpt _finish _finish nopanel true - The Aggregate Table has access to all attributes on the incoming pipe.
- In the Attribute expressions,
- Use functions to aggregate values e.g. sum(in.Amount) will sum up all amounts within a group.
- Where multiple values exist for a group they will be treated as an array. Use a fullstop suffix after the attribute name followed by a number to obtain the record from a group in that position. e.g. in.Name.1 will take the first name in a group. Alternatively, use the Functions built into PhixFlow to select the required value.
Aggregate Examples
See Using an Aggregate StreamTable
Aggregate Functions
This is the list of available aggregate functions.
Function | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Average | This function returns the arithmetic average value of an attribute from records with the same key value. In detail, it returns the sum of all values for a key value, divided by the number of values that are not null. It is only available for numeric attributes. | ||||||||||||||||||||||||
Count | This function returns the number of non-null values of an attribute from records with the same key value. | ||||||||||||||||||||||||
Distinct | This function returns the number of unique values of an attribute from records with the same key value. Distinct is only available to use when aggregating on a pipeThere is no single attribute function equivalent of the distinct pipe function. | ||||||||||||||||||||||||
Maximum | This function returns the maximum value of an attribute from records with the same key value. It is available for numeric, string and date/time attributes. Strings are ordered alphabetically, with the shortest strings first. | ||||||||||||||||||||||||
Minimum | This function returns the minimum value of an attribute from records with the same key value. It is available for numeric, string and date/time attributes. Strings are ordered alphabetically, with the shortest strings first. | ||||||||||||||||||||||||
Percent |
This function can be applied to a numeric field, to return the percentage of the sum of values for each key value in relation to the total sum of values. You should use this function in conjunction with one or more grouping attributes - each combination of values from these grouping attributes gives a key value. For example, you have a stream with 2 fields:
and you create a grid view:
This will give the view:
| ||||||||||||||||||||||||
Sum | This function returns the sum of all values of an attribute from records with the same key value. It is only available for numeric attributes. |