Skip to content

Custom Formula Functions

Last updated: February 12, 2024

Available with any of the following subscriptions, except where noted:

Operations Hub Professional, Enterprise

If you're using a custom formula to format your data in a workflow, you can use functions with property values from the enrolled record or outputs from previous actions to create complex formulas. 

Review the different functions below to determine which to use: 

Function Description Example
abs Retrieve the absolute value of a number. You can use this function to make sure that a number is positive.
  • example formula: abs([number or number property])
    • example: abs(-10) 
    • example output: 10
add Adds a numeric value to another numeric value. This function is the same as the + operator. Use with the following: 
  • number: the initial numeric value for the operation.
  • number to add: the number to be added to the initial numeric value. 
  • example formula: add(number, number to add)
    • example: add(5, 10)
    • example output: 15

Alternatively, you can also use:

  • example formula: number + number to add
    • example: 5+10
    • example output: 15
concat Combine multiple string values. This function is only available when the Format data action is used in Custom mode
  • example formula:concat([string 1], " ", [string 2]) 
    • example: concat([company name], " ", [MonthYear])
    • example output: HubSpot June 2006
capitalize Capitalize the first letter of a string value. The first character will be uppercase, while all others letters will be lowercased. Other words in the input won't have their first letter uppercased
  • example formula: capitalize([string])
    • example: capitalize([firstname])
    • example output: Henry
cut Cut a character or multiple characters to removes a string from a value. This function can be used to match and cut out a specific part of a string. The parameter specifies the part of the string that should be removed. Use with the following: 
  • source: the source string to remove characters from. 
  • characters_to_cut: the specific characters to remove. This format is case sensitive. 
  • formula: cut(source, characters to cut)
    • example: cut([phone], "-")
    • example output: 80081234567 


datetimeformat

Please note: this formula has been deprecated and replaced by the format_datetime function below. Actions using this function will continue to work, but the new function should be used moving forward.

 
format_datetime Convert a timestamp into a human-friendly format. Include the timestamp or property along with the following parameters to configure its format:
  • format: the format to use. Values include: 'short', 'medium', 'long', 'full'. You can also specify a custom format using Unicode LDML patterns.
  • timeZone: the time zone of the output data in IANA TZDB format. By default, returns UTC time.
  • locale: the locale to use for locale-aware formats.
  • formula: format_datetime(date, format, timeZone, locale)
    • example: format_datetime([closedate], 'medium', 'America/New_York, 'de-DE')
    • example output: 08.02.2024, 17:09:49
divide Divide a number. This function is an alternative to the / operator. Use with the following: 
  • number: the number to divide. 
  • divisor: the number to divide by for the divide operation. 
  • formula: divide(number, divisor)
    • example: divide (8, 4)
    • example output: 2

Alternatively, you can also use: 

  • formula: number/divisor
    • example: 8/4
    • example output: 2
divisible Test if a number is evenly divisible. When there is no remainder, this function will evaluate to true. When there is a remainder, this function will evaluate to false. Use with the following: 
  • number: the number to divide. 
  • divisor: the number to divide by for the divide operation. 
  • formula: divisible(number, divisor)
    • example: divisible (5,2)
    • example output: false
join Combine two or more strings into one result string, using a separator between each value. This function is only available when the Format data action is used in Custom mode

Use with the following: 
  • delimiter: a separator string to be inserted between each item.
  • items: any number of strings to combine. 
  • formula: join(delimiter, items)
    • example: join("-", "A", "B", "C")
    • example output: A-B-C
left Returns a substring of characters from a string value from a beginning of a string value. This function is only available when the Format data action is used in Custom mode.
  • formula: left(string, length)
    • example: left("Maria", "1")
    • example output: M


length Returns the number of characters in a string.
  • formula: length(string)
    • example: left("Hello World!")
    • example output: 12
lower Convert all characters in a string to all lowercase letters.
  • formula: lower([string])
    • example: lower(["HELLO WORLD"])
    • example output: hello world
mid Returns a substring of characters from a string value. This function is only available when the Format data action is used in Custom mode.
  • formula: mid(string, start-index, length)
    • example: join("abc123", 2, 2)
    • example output: c1
minus_time Subtracts an amount of time from a date/time object. Use with the following: 
  • datetime: the date/time object to add time to.
  • diff: the amount of time to add. 
  • timeunit: the unit of time to be added. The following can be used: 
    • seconds
    • minutes
    • hours
    • half_days
    • days
    • weeks
    • months
    • years
  • formula: minus_time(datetime, diff, timeunit)
    • example: minus_time([closedate], 2, "days")
    • example output: 04/11/2020
multiplier Multiplies a value by a number. This function is an alternative to the * operator. Use with the following: 
  • number: the number to multiply.
  • multiplier: the number to multiply by. 
  • formula: multipler(number, multipler)
    • example: multiplier(5, 3) 
    • example output: 15

Alternatively, you can also use:

  • formula: number*multipler
    • example: 5*3 
    • example output: 15
number Converts a string to a number.
  • formula: number(string, default?)
    • example: left("36")
    • example output: 36
plus_time Add an amount of time to a date/time object. Use with the following: 
  • datetime: the date/time object to add time to.
  • diff: the amount of time to add. 
  • timeunit: the unit of time to be added. 
  • formula: plus_time(datetime, diff, timeunit)
    • example: plus_time([closedate], 2, "days")
    • example output: 06/11/2020


randomNumber Generate a random number within a range.

With this function, the numbers generated are completely random and may repeat. For example, if you used a range of one to three and enrolled three contacts, you may not get three unique numbers. 

Both minimum and maximum numbers are included in the range. You can also use 0 and negative numbers when setting your range. 
  • formula: randomNumber(minimum, maximum)
    • example: randomNumber(1, 3)
    • example output: 1 or 2
replace Replace all instances of a substring with a different string. Use with the following: 
  • string: the string to search for and replace. 
  • old: the substring that should be replaced. 
  • new: the replacement string. 
  • count: the number of instances of the substring to replace. If not provided, all substrings will be replaced
  • formula: replace(string, old, new, count)
    • example: replace( "Hello world!", "Hello", "Hi", 1)
    • example output: Hi world!
right Returns a substring of characters from a string value from the end of a string value. This function is only available when the Format data action is used in Custom mode.
  • formula: right(string, length)
    • example: right("abc123", 3)
    • example output: 123
root Calculate the square root of a number. Optionally, specify the Nth root to calculate. Use with the following:
  • number: the number to take the root of.Calculate the square root of a number. Optionally, specify the Nth root to calculate 
  • nthRoot: the nth root to be calculated. If not specified, the square root will be taken. 
  • formula: root(number, nthRoot)
    • example: root(625, 4)
    • example output: 5
round Round a number to a specified decimal. Use with the following:
  • precision: the decimal to round to. 
  • rounding method: round up or down to the nearest whole number. The following rounding methods can be used: 
    • common
    • ceil
    • floor
  • formula: round(number, precision, rounding method)
    • example: round(52.5, 0, 'floor')
    • example output: 52
striptags Strip SGML/XML tags and replace adjacent whitespace by one space. This filter can be used to remove any HTML tags from a variable.
  • formula: striptags([string])
    • example: striptags(<div><p>Potato</p></div>)
    • example output: Potato
title Change text to title casing. Each word in the resulting string will start with uppercase letters, while all remaining characters are lowercase.
  • formula: title([string])
    • example: title("cheddar CHEESE")
    • example output: Cheddar Cheese
trim Remove leading and trailing whitespace from a string.
  • formula: trim([string])
    • example: trim(" peach ")
    • example output: peach
unixtimestamp Convert a date/time object into a Unix timestamp.
  • formula: unixtimestamp([dateteime])
    • example: unixtimesstamp([closedate])
    • example output: 1652863824
upper Change all characters to uppercase.
  • formula: upper([string])
    • example: upper("teatime")
    • example output: TEATIME
urlencode Escape and URL encode a string using UTF-8 formatting.
  • formula: urlencode([string])
    • example: urlencode("hi there")
    • example output: hi%20there
Was this article helpful?
This form is used for documentation feedback only. Learn how to get help with HubSpot.