Aggregate Operator: Max By
Overview
Let's say your configuration calls for finding the highest number in a data set. You'll use the Max By function of the Data Workflow Aggregate operator to do that.
For example, say you have a Data Table that holds several dogs' ages. And you know the oldest dog should get the most treats. To solve this, you'll create a Data Workflow to find and return the name of the oldest dog.
Here's how your module will look in the Module Builder:
Here's how the completed use case will look in Express View, including a peek at the DevTools Console:
What You'll Learn
In this article, you'll learn how to use the Aggregate operator's Max By function.
What You'll 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, you'll add your Data Table. This will hold the information you'll bring into your Data Workflow. Here, you'll set up a list of dogs, storing their name and age.
1. | Drag and drop a Data Table onto your canvas. |
2. | Enter dtDogs in the Label and Property Name. |
3. | In the data table, enter the following: |
A |
B |
---|---|
name |
age |
Ivy |
7 |
Lucy |
10 |
Wally |
1 |
Nacho |
5 |
Thor |
5 |
Holly |
13 |
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 find the oldest dog. Finally, you'll show the result using a Console operator.
1. | Drag and drop a Data Workflow onto your canvas. Place your Data Workflow below your Data Table. |
2. | Enter dwfOldest in the Canvas Label Text and Property Name. |
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 |
Oldest Dog |
Aggregation Type |
Max By |
Join Group Keys |
No |
Group Key |
|
Value Key |
age |
3. | Connect the output port (right) of the Input operator to the input port (left) of the 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 |
Who is the oldest dog? |
3. | Connect the output port (right) of the Aggregate operator to the input port (left) of the Console operator. |
4. | Click Save. |
Configure the Button Component
Now, you'll add a Button component to start the operation. Clicking your button fires your Data Workflow. From there, your Data Workflow takes all the ages and finds the oldest.
1. | Drag and drop a Button component onto your canvas. Place your Button below your Data Workflow. |
2. | Enter btnOldestDog in the Property ID. |
3. | Enter Find Oldest Dog in the Label Text. |
4. | Select Event from the Button Action Type. |
5. | Enter dwfOldest in the Trigger on Click. |
6. | Click Save. |
7. | Save your module. |
Once finished, preview your module in Express View and open the DevTools Console. Next, click your button. You'll see the oldest dog next to the label from your Data Workflow: Who is the oldest dog?
Lab
You can view this complete use case here: https://training.unqork.io/#/form/5f6a606f19c4e6024ed1e598/edit.