Formula Operator

Estimated Reading Time:  8 minutes

Overview

The Formula operator lets you run your data through a calculation and send it to an output. Let's say you're calculating the cost of an insurance plan over time and you know the value for one month. To find the value for a year, you use a Formula operator to multiply your original value by 12. Another common use for this operator is to find percentages of a whole.

You have two options when creating your formula:

  • Creating a static formula using the Formula's Info window.

  • Creating a formula with dynamic values using the operator's argument port.

You’ll find the Formula operator under the Table group in the menu on the Data Workflow canvas.

What You'll Learn

In this article, you'll learn:

Info Window Settings

Here's what the Formula operator looks like, along with its Info window:

A static image displaying the Formula operator and its Settings Info window.

And here's a breakdown of each setting in the Info window:

Setting

Description

Label

The name applied to the operator. This label displays within the workflow. Labels should be user-friendly and well associated with the role of the operator.

Preserve Argument Type

When selected, this setting ensures the argument data type is respected when the operator executes.

Formula/Expression

The formula or expression you want to apply to your data. Here, use A to represent your original data. Your original data is anything you bring in through the operator's input port. Let's say you want to multiply your data by 12. To do that, you enter =A*12 in this field.

If you want to use an argument instead of a set value in your formula, use _arg. So, the above formula with an argument looks like this: =A*_arg. In this example, _arg takes the place of 12. Whatever value is set in the argument port goes in its place.

Adding and Configuring a Formula Operator

To show the Formula operator in action, let's look at an example. This example uses a standard monthly insurance rate set in a Number component. Your end-user has the choice of how long they need coverage. From there, a Data Workflow uses a Formula operator to calculate the cost of coverage.

Here's how the completed use case looks in the Module Builder:

A static image displaying the Formula operator completed use case in the Module Builder.

Here's how the completed use case looks 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.:

Static image displaying the Formula operator use case data in the DevTools Console.

Configure the Text Field Components

Start by adding your Text Field components. Your first Text Field holds the monthly cost of insurance. The second holds the total cost based on how many months of coverage your end-user wants. Since your values here are always monetary, set a dollar sign as the prefix. Your end-users don't need to enter anything in these fields either, so set them both to disable user input.

1. Drag and drop two  Text Field components 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 Label Text Label Text conveys what the input component is and what information it displays. Enter the purpose of the corresponding component or field. fields, enter the following:

Property ID

Label Text

monthlyCost

Monthly Cost

totalCost

Total Cost

3. In the Prefix field, enter $ .
4. Set the Disable User Input toggle to (ON).
5. Save & Close each component as you add it.

Configure the Initializer Component

Next, add your Initializer component. Every time an end-user opens a new submission, your Initializer places a value of 1000 in your first Text Field. This lets the Initializer manage the monthly cost. If you want to set a new monthly cost, all you have to do is update this Initializer.

1. Drag and drop an Radio Button component icon Initializer component onto your canvas, placing it above your  Text Field 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. 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 initSetCost.
3. Set the Trigger Type Deteremines how the component triggers. as Manual The component fires when the page or called module loads without an existing submission ID. Dashboards and remote execute modules are great uses for this trigger..
4. In the Outputs Enter outputs components and actions you want the component to perform. table, enter the following:
 

Property ID

Type

Value

1

monthlyCost

value

1000

Static image showing the Initializer configuration in the Formula operator use case.

5. Click Save & Close.

Configure the Dropdown Component

Now, give your end-user a way to select how many months they want coverage. Use a Dropdown component for that. This component serves as the argument for your Formula operator.

1. Drag and drop a Dropdown Component Icon Dropdown component onto the canvas, placing it between your  Text Field 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 coverageLength.
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. field, enter How many months of coverage do you need?.
4. In the Values table, enter the following:

Option Label

Option Value

6

6

12

12

18

18

24

24

5. Click Save & Close.

Configure the Data Workflow Component

Now you can add your Data Workflow component, bringing your monthly cost into the Data Workflow using an Input operator. A second Input operator brings in your end-user's selection from the Dropdown. Then, a Formula operator calculates the total cost. The final value is sent to your Text Field using an Output operator.

1. Drag and drop a Data Workflow Icon Data Workflow component onto your canvas, placing it below your other components.
2. In the Canvas Label Text and Property Name fields, enter dwfCost.
3. Set the Trigger Type Deteremines how the component triggers. to Watch.

Static image displaying the Data Workflow configuration for the Input Switch operator.

Configure the First Input Operator

This Input operator references data from your monthlyCost  Text Field component.

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

monthlyCost

Required

Yes

Source

Default

Configure the Second Input Operator

This operator draws your end-user's requested coverage length.

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

Setting

Value

Category

Input

Component

coverageLength

Required

Yes

Source

Default

Configure the Formula Operator

This operator multiples the monthly cost (A) by your end-user's coverage length, which serves as the formula's argument (_arg).

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

Setting

Value

Category

Formula Value

Label

Total Cost

Preserve Argument Type

Unchecked (no)

Formula/Expression

=A*_arg

3. Connect the output port (right) of the monthlyCost Input operator to the input port (left) of the Formula operator.
4. Connect the output port (right) of the coverageLength Input operator to the argument port (top) of the Formula operator.

Configure the Output Operator

This Output operator sends the final cost to your totalCost  Text Field component.

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

totalCost

Action

value

3. Connect the output port (right) of the Formula operator to the input port (left) of the Output operator.
4. Click Save.
5. Save your module.

Now, preview your module in Express View and make a selection from the Dropdown. Depending on your selection, you see the calculated total cost in the Total Cost field. When you make a new selection, the total cost updates.

Resources