Aggregate Operator

Estimated Reading Time:  8 minutes

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 article, we'll focus on the Sum By operation. Let's say you have a data table containing various dog names and their weight in pounds. Then, you want to sum all the weights and output the total. The Aggregate operator can sum of every weight in that column and output the total.

IMPORTANT  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:

A static image displaying the Aggregate operator and its 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:

  • Sum By: Evaluates the value in the Value Key field and adds all number values for a range.

  • Count By: Evaluates the value in the Value Key field and counts the number of cells containing number values.

  • Mean By: Evaluates the value in the Value Key field and calculates the average.

  • Max By: Evaluates the value in the Value Key field and determines the highest value.

  • Min By: Evaluates the value in the Value Key field and determines the lowest value.

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.

TIP  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.

IMPORTANT  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.

TIP  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:

To set up your Data Workflow, you need:

NOTE  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.

1. In the Module Builder, drag and drop a Dropdown Component Icon Data Table onto your canvas.
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 dtDogs.
3. To the left of the component's configuration window, click Data Icon Data.
4. In the data table, enter the following:

A

B

name

weight

Ivy

60

Lucy

80

Wally

20

Nacho

10

Thor

50

Holly

100

5. Click Save & Close.

A static image displaying the Data Table component's completed configuration in the configuration window.

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 Icon Data Workflow onto your canvas, placing it below the Dropdown Component Icon 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.

A static image displaying the Data Workflow component's completed configuration in the configuration window.

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 Icon Button component onto your canvas, placing it between your Dropdown Component Icon Data Table and Data Workflow Icon 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 Icon Actions.
5. Set the Action Type as Event.
6. From the On Click drop-down, select dwfWeight.

A static image displaying the Button component's completed configuration in the configuration window.

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 Icon 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:

A static image displaying the completed configuration in the Module Builder.

Preview your module in Express View Express View is how your end-user views you 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.

A static image displaying the data returned in the DevTools Console in Express View.

Resources

Lab

You can view this complete use case here: https://training.unqork.io/#/form/5f6a653e19c4e6024ed1e613/edit.