Aggregate Operator: Min By

Overview

If you need to find the lowest value in a data set, the Data Workflow Aggregate operator will do the trick. You'll use the Min By function to find your results.

Say you have a Data Table with a list of dogs and their ages. You're looking for the youngest dog to make sure they get extra playtime. You can create a Data Workflow that returns the name of the youngest 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 Min 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 data 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:

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 youngest 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 dwfYoungest 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

Youngest Dog

Aggregation Type

Min 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 youngest 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 youngest.

1. Drag and drop a Button component onto your canvas. Place your Button below your Data Workflow.
2. Enter btnYoungestDog in the Property ID.
3. Enter Find Youngest Dog in the Label Text.
4. Select Event from the Button Action Type.
5. Enter dwfYoungest in the Trigger on Click.

6. Click Save.
7. Save your module.

When you're done, preview your module in Express View and open the DevTools Console. Next, click your button. You'll see the youngest dog next to the label from your Data Workflow: Who is the youngest dog?

Lab

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