Aggregate Operator
Overview
The Data Workflow Aggregate operator lets you perform one of five operations on your data set:
-
Sum By: Adds all numbers in a given range.
-
Count By: Counts the number of values in a given range that contain numeric values.
-
Mean By: Calculates the average of values in a given range.
-
Max By: Finds the highest value in a given range.
-
Min By: Finds the lowest value in a given range.
In this
How you sum values is based on JavaScript JavaScript is an object-oriented computer programming language. It is most-commonly used for interactive effects in the browser.. If you input a single value of null, it returns null and an error message in the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.. If you input two values of null, the operator sums them and returns a value of 0.
Similar Data Workflow Operators
The Aggregate operator is similar to the Append operator. Here are the operators compared:
-
Aggregate operator: Performs calculations on two or more numbers. This operator supports the Sum By, Count By, Mean By, Max By, and Min By operations.
-
Append operator: Combines strings or arrays together. When appending strings, the operator performs a concatenation on the values. When appending arrays, it combines the arrays into one.
What You'll Learn
In this article, you'll learn when to use an Aggregate operator, how to configure its settings, and understand the best practices.
About the Info Window
Here's a breakdown of each setting in the Info window:
Setting |
Description |
---|---|
Label |
Sets the label for your operator. The label you enter here shows beneath your operator on your Data Workflow canvas. This field is optional, but set a label if you use more than one of the same operator type. A label helps you identify your operators without opening any Info windows. |
Aggregation Type |
Sets the operation to perform on your data. You have the choice of:
You can only choose one operation for each operator. But you can have as many Aggregate operators in your Data Workflow as you need. Use labels to keep track of each operator. |
Join Group Keys |
When you select YES, your operator creates a new column that joins the values of your individual Group Keys. For example, say you're working with the dog information data set from above. You might have columns for age and breed. If you aggregate these two columns, selecting YES returns a column called age-breed. And your resulting values display in the same format: 12-chow. |
Group Key |
This field lets you separate your selected operation into categories. Let's say you want to calculate the mean dog weight in your data tablefor each dog breed. If you have a column labeled breed, you'll enter breed in the Group Key field. That way, the operator treats each unique value in the breed column as its own group. Your Data Workflow then returns a mean value for each group. When entering more than one Group Key, separate each using a comma. To see a Group Key in action, visit the Aggregate Operator: Count By Use Case article. |
Value Key |
This filed lets you enter a data table column header to perform an operation on. Let's say you have a column header of cost and you want to calculate the sum of all values in that column. You'll enter cost in the Value Key field. Or, maybe you are using the operator to find the highest value in a column with a header of age. Then, you'll enter age into this field. The Value Key field is case-sensitive and must match your column header exactly. |
Adding a Sum By Aggregate Operator
In this example, you'll create a configure a Data Table component to store various dog names and their weights in pounds. Then, you'll configure a Data Workflow that sums all the weights.
This use case focuses on the Sum By function of the Aggregate operator. You can find other use cases in the Resources section of this article.
What You Need
To complete this configuration, you need:
-
1 Data Table component
-
1 Button component
-
1 Hidden component
-
1 Data Workflow component
To set up your Data Workflow, you need:
These instructions assume you have a new module open and saved with a title.
Configure the Data Table Component
First, you'll configure a Data Table component to store your data and input it into a Data Workflow component.
|
Configure the Data Workflow Component
Next, you'll configure a Data Workflow component to retrieve the stored data and use an Aggregate operator to calculate the sum of your weight column. Then, you'll output the summed value and store it in a Hidden component.
1. | Drag and drop a Data Workflow onto your canvas, placing it below the Data Table component. |
2. | In the Label and Property Name fields, enter dwfWeight. |
Configure the Input Operator
1. | Drag and drop an Input operator onto your Data Workflow canvas. |
2. | Configure the Input operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Input |
Component |
dtDogs |
Required |
Yes |
Source |
Default |
Configure the Aggregate Operator
1. | Drag and drop an Aggregate operator onto your Data Workflow canvas. |
2. | Configure the Aggregate operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Aggregate By |
Label |
Total Weight |
Aggregation Type |
Sum By |
Join Group Keys |
No |
Group Key |
|
Value Key |
weight |
3. | Connect the output port (right) of the Input operator to the input port (left) of the Aggregate operator. |
Configure the Output Operator
1. | Drag and drop an Output operator onto your Data Workflow canvas. |
2. | Configure the Output operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Output |
Component |
sumWeight |
Action |
value |
3. | Connect the output port (right) of the Aggregate operator to the input port (left) of the Output operator. |
4. | Click Save. |
Configure the Button Component
Now, add a Button component to launch the whole operation. Clicking the button fires your Data Workflow. From there, your Data Workflow takes care of the rest by calculating the summed weight.
1. | Drag and drop a Button component onto your canvas, placing it between your Data Table and Data Workflow components. |
2. | In the Property ID A Property ID is the unique field ID used by Unqork to track and link components in your module. field, enter btnTotalWeight. |
3. | In the Label Text field, enter Find Total Weight. |
4. | To the left of the component's configuration window, click Actions. |
5. | Set the Action Type as Event. |
6. | From the On Click drop-down, select dwfWeight. |
7. | Click Save & Close. |
Configure the Hidden Component
Lastly, you'll configure a Hidden component to store the summed value.
1. | Drag and drop a Hidden component onto the canvas, placing it below your Data Workflow component. |
2. | In the Property ID A Property ID is the unique field ID used by Unqork to track and link components in your module. and Canvas Label Text fields, enter sumWeight. |
3. | Click Save & Close. |
4. | Save your module. |
Below is the completed configuration in the Module Builder:
Preview your module in Express View Express View is how your end-user views your application. Express View also lets you preview your applications to test your configuration and view the styling. This is also the view your end-users will see when interacting with your application. After configuring a module, click Preview in the Module Builder to interact with the module in Express View. and open the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.. Click the button and run the Angular Command The Angular command, or data command, is a tool that displays submission data in a browser's developer console. In Express View, enter the following command in the devtool console: angular.element('.unqorkio-form').scope().submission. Expand the data and you'll see the total weight stored in the sumWeight Hidden component.
Resources
Lab
You can view this complete use case here: https://training.unqork.io/#/form/5f6a653e19c4e6024ed1e613/edit.