Mathematical functions

When you're building workflows in Tines, you'll often need to perform calculations on numbers. Maybe you need to add up invoice totals, calculate the average response time for support tickets, or generate a random number for testing. Mathematical functions help you perform calculations and analyze numeric data.

Think of mathematical functions as your calculator tools. They help you add, average, and generate numbers to support decision-making and data analysis in your workflows.

Tines offers multiple mathematical functions to handle common numeric tasks. We'll look at the following in this section:

  • SUM - Adds up all numbers passed.

  • AVERAGE - Calculates the mean (average) of numbers.

  • RANDOM - Generates a random number within a given range.

SUM: Add numbers together 

The SUM function adds up all the numbers in an array and returns the total. This is useful when you need to calculate totals, aggregate values, or combine multiple amounts.

Basic syntax 

SUM(array)

Example 

Let's look at an array of item prices (coming from an upstream action called "Get Items"):

{
  "item_prices": [
    15.99,
    60,
    98.75
  ]
}

We want to add up the total of these prices. To do that, we execute the following formula via the Value pill in a downstream, connected action:

SUM(get_items.item_prices)

The output equals the total amount of the items:

174.74

AVERAGE: Calculate the mean 

The AVERAGE function calculates the average (mean) of numbers in an array. This is useful for finding typical values, analyzing trends, or calculating performance metrics.

Basic syntax 

AVERAGE(array)

Or, you can pass in numbers manually:

AVERAGE(number1, number2, number3, ...)

Example 

Let's look at an array of survey scores (coming from an upstream action called "Get Surveys"):

{
  "scores": [
    8,
    3,
    8,
    6,
    10
  ]
}

We want to calculate the average of all the scores. To do that, we execute the following formula via the Value pill in a downstream, connected action:

AVERAGE(get_surveys.scores)

The output equals the average across all scores:

7

RANDOM: Generate random numbers 

The RANDOM function generates a random number within a specified range. This is useful for testing, sampling, or creating unique identifiers.

Basic syntax 

RANDOM(min, max)

Example 

Let's look at an example of setting up some student data:

{
  "name": "Ryan Brown",
  "email": "rbrown@company.com",
  "class": "Builder",
  "group": ""
}

We want to assign this student to a random group for a project (let's say we have 5 groups total). To do that, we execute the following formula via the Value pill for the "group" key:

RANDOM(1, 5)

The output picks a random (group) number from our minimum and maximum values:

{
  "name": "Ryan Brown",
  "email": "rbrown@company.com",
  "class": "Builder",
  "group": 3
}

🪄Tip

Was this lesson helpful?

Built by you,
powered by Tines

Already have an account? Log in.