Aggregate Operator: Count By Using Group Key

Overview

The Aggregate operator is used to count the number of entries in a data set using the Count By function. You can also use the operator’s Group Key field, which allows you to group the results into categories based on values from the original data.

For example, consider a Data Table that holds the details of several dogs, including their favorite foods. You can create a Data Workflow to count how many dogs have the same favorite food. In this case, each kind of food will show as a separate category with the help of Group Key field.

Here's how your module will look in the Module Builder:

A static image displaying the configuration to count the favorite foods.

Here's how the use case will look in Express View, including a peek at the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.:

A static image displaying the favorite food count configuration in the Express View.

Configuration

Configure the Data Table Component

First, you'll add a Data Table to hold the data that you'll bring into your Data Workflow. Here, you'll set up a list of dogs, storing their name and favorite food.

1. In the Module Builder, drag and drop a Data Table component 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. , enter dtDogs.
3. In the data table, enter the following:
 

A

B

1

name

favoriteFood

2

Ivy

Peanut Butter

3

Lucy

Beef Jerky

4

Wally

Peanut Butter

5

Nacho

Peanut Butter

6

Thor

Salmon

7

Holly

All Foods

A static image displaying the data table with the dog names and their favorite food.

4. Click Save Component.

Configure the Data Workflow Component

Next, you'll add your Data Workflow component. You'll bring your data into the Data Workflow using an Input operator. Then, you'll add an Aggregate operator to count how many dogs have the same favorite food. But to get an accurate count, you'll need to count the names associated with each favorite food. So, you'll set the Aggregate operator to use the Value Key of name and the Group Key of favoriteFood. And lastly, you'll show the result using a Console operator.

1. In the Module Builder, drag and drop a Data Workflow component onto your canvas, placing it below your your dtDogs Data Table.
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 Canvas Label Text indicates the purpose of the corresponding field or component. For non-input components, the Canvas Label Text isn't end-user facing, and only appears in the . fields, enter dwfFavoriteFood.

A static image displaying the data workflow, which is used to count the favorite dog foods.

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

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

Setting

Value

Category

Aggregate By

Label

Favorite Food Counts

Aggregation Type

Count By

Join Group Keys

Yes

Group Key

favoriteFood

Value Key

name

3. Connect the output port (right) of the dtDogs Input operator to the input port (left) of the Favorite Food Counts Aggregate operator.

Configure the Console Operator

1. Drag and drop a Console operator onto your Data Workflow canvas.
2. Configure the Console operator's Info window as follows:
Info

Category

Console

Label

How many dogs have the same favorite food?

3. Connect the output port (right) of the Favorite Food CountsAggregate operator to the input port (left) of the How many dogs have the same food?Console operator.
4. Click Save Component.

Configure the Button Component

Now, you'll add a Button component to start the whole operation. Clicking the button fires your Data Workflow, to count the number of dogs who have the same favorite food.

1. Drag and drop a Button component Icon Button component onto your canvas, placing it below the 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., enter btnFavoriteFood.
3. In the Label Text Label Text conveys what the input component is and what information it displays. Enter the purpose of the corresponding component or field., enter Count Favorite Foods.
4. From the Action Type drop-down, select Event.
5. From the Triggers On click drop-down, select dwfFavoriteFood.

A static image displaying the button component which triggers the data workflow component.

6. Click Save Component.
7.  Save  your module.

Now, preview your module in Express View and open the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.. Next, click your button. You'll see a list of each food mentioned in your Data Table. Along with each food, you'll see how many dogs love it!

A static image displaying the table data in the Dev tools console.

Lab

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

Overview

The Aggregate operator counts how many entries are in a data set. To do this, you'll use the Aggregate Operator with the Count By function to calculate the number of entries in a data set. You can also use the operator's Group Key field while performing this operation. This lets you separate the operation into categories based on your original data.

For example, consider a Data Table that holds the details of several dogs, including their favorite foods. You can create a Data Workflow to count how many dogs have the same favorite food. In this case, each kind of food will show as a separate category with the help of Group Key field.

Here's how your module will look in the Module Builder:

A static image displaying the configuration to count the favorite foods among dogs.

Here's how the completed use case will look in Express View, including a peek at the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.:

A static image displaying the complete usecase on the express preview.

What You Need

To set up this use case, you’ll need:

  • 1 Data Table component

  • 1 Button component

  • 1 Data Workflow component

To set up your Data Workflow, you'll need:

  • 1 Input operator

  • 1 Aggregate operator

  • 1 Console operator

These instructions assume you have a new module open, saved, and with a title.

Configuration

Configure the Data Table Component

First, let's add your Data Table. This will hold the data you'll bring into your Data Workflow. Here, you'll set up a list of dogs, storing their name and favorite food.

1. Drag and drop a Data Table onto your canvas.
2. In the Label Text Label Text conveys what the input component is and what information it displays. Enter the purpose of the corresponding component or field. and Property ID A Property ID is the unique field ID used by Unqork to track and link components in your module., enter dtDogs.
3. In the data table, enter the following:

A

B

name

favoriteFood

Ivy

Peanut Butter

Lucy

Beef Jerky

Wally

Peanut Butter

Nacho

Peanut Butter

Thor

Salmon

Holly

All Foods

A static image displaying the data in the Data Table.

4. Click Save.

Configure the Data Workflow Component

Next, you'll add your Data Workflow component. You'll bring your data into the Data Workflow using an Input operator. Then, you'll add an Aggregate operator to count how many dogs have the same favorite food. But to get an accurate count, you'll need to count the names associated with each favorite food. So, you'll set the Aggregate operator to use the Value Key of name and the Group Key of favoriteFood. Finally, you'll show the result using a Console operator.

1. Drag and drop a Data Workflow onto your canvas, placing it below your Data Table.
2. In the Canvas Label Text Canvas Label Text indicates the purpose of the corresponding field or component. For non-input components, the Canvas Label Text isn't end-user facing, and only appears in the . and Property ID A Property ID is the unique field ID used by Unqork to track and link components in your module. fields, enter dwfFavoriteFood.

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

Favorite Food Counts

Aggregation Type

Count By

Join Group Keys

Yes

Group Key

favoriteFood

Value Key

name

3. Connect the output port (right) of the dtDogs Input operator to the input port (left) of the Favorite Food Counts Aggregate operator.

Configure the Console Operator

1. Drag and drop a Console operator onto your Data Workflow canvas.
2. Configure the Console operator's Info window as follows:

Setting

Value

Category

Console

Label

How many dogs have the same favorite food?

3. Connect the output port (right) of the Favorite Food CountsAggregate operator to the input port (left) of the How many dogs have the same food?Console operator.
4. Click Save.

Configure the Button Component

Now, you'll add a Button component to start the whole operation. Clicking the button fires your Data Workflow, to count the number of dogs who have the same favorite food.

1. Drag and drop a Button component Icon Button component onto your canvas, placing it below the 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., enter btnFavoriteFood.
3. In the Label Text Label Text conveys what the input component is and what information it displays. Enter the purpose of the corresponding component or field., enter Count Favorite Foods.
4. From the Button Action Type drop-down, select Event.
5. From the Trigger On click drop-down, select dwfFavoriteFood.

6. Click Save.
7. Save your module.

Now, preview your module in Express View and open the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.. Next, click your button. You'll see a list of each food mentioned in your Data Table. Along with each food, you'll see how many dogs love it!

A static image displaying the data in the Express View.

Lab

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