Use date and number formulas in the Action element

Formulas can help you calculate values in variables of the Number and Date types. This way, you can automatically determine the next event date, measure the time span between dates, or process numeric values.

In this article, we will talk about how to use formulas.

Basics

A formula is a mathematical expression that the system calculates and saves its result to a specific variable.

First, the system substitutes current variable values into your formula, then calculates, checks, and assigns the result to another variable.

Add an element and select an action

Drag the Action element right after the relevant element and select Other > Change contact variable.

This action overwrites your selected variable only within your current flow and email mailing lists. The original variables keep their values.

In the Variable field, choose a variable of the Number or Date type.

Select the Insert formula checkbox. In the Variable value field, choose a variable and add operations based on the variable type.

Use formulas in variables

Formulas support variables of the Number and Date types. They do not process arrays or text values in String variables. However, if a String variable contains a number, you can still apply formulas to it.

Formulas are calculated for each contact individually to provide accurate and personalized flows. When you use formulas, the system validates them using the following rules:

  • Variable types must match the expected format.
  • Numbers cannot exceed 10,000.
  • Division by zero is not allowed.
  • Text values and syntax errors are not permitted.

If a formula returns an invalid value, your variable will not be updated.

Date

Date variables support addition and subtraction. Formulas always calculate the difference in full days. This helps measure time between dates, such as the number of days since a purchase or until a subscription expires.

You can only use numbers to perform operations since date-to-date calculations are not supported.

As an example, you can use {{purchase_day}} + 3, where {{purchase_day}} is the purchase date. Here, the customer has three days to claim a discount on their next order. On the last day of the offer, you can schedule extra marketing activities using the updated date variable.

Calculations only use dates, so time values in variables are ignored. If you add or subtract a decimal number from a date, the fractional part is ignored. For example, adding or subtracting 1.5 shifts the date by 1 day.

You can also add the CurrentDate system variable, which returns the current date.

Number

Number variables support addition, subtraction, multiplication, and division.

For example, to apply a 20% discount, use the following formula:
{{price}} - ({{price}} * 0.2).

If a variable with the same name exists in both an event and a mailing list, the event variable takes priority. Similarly, custom variables have priority over system variables.

Rate this article about "Use date and number formulas in the Action element"

User Rating: 4 / 5 (7)

Previous

Set up sending webhooks to your system

Popular in Our Blog

Try SendPulse email service for free