Create calculation properties
Last updated: September 5, 2024
Available with any of the following subscriptions, except where noted:
Marketing Hub Professional , Enterprise |
Sales Hub Professional , Enterprise |
Service Hub Professional , Enterprise |
Operations Hub Professional |
Content Hub Professional , Enterprise |
You can create properties that populate data based on calculations from other properties. With calculation properties, you can set up custom equations based on other properties. With rollup properties, you can automatically calculate the min, max, count, sum, or average values for properties on associated records.
For example, you can create:
- A company property that calculates the cost to acquire a new customer based on a custom equation.
- A contact property that calculates the average Amount of a contact's associated deals.
Please note: depending on your HubSpot subscription, there is a limit to the number of calculation properties you can create.
Create calculation properties
Calculation properties can be set up based on different criteria, including property values of associated records, the time between two properties' values, or your own custom equations. To create a calculation or rollup property:
- In your HubSpot account, click the settings settings icon in the top navigation bar.
-
In the left sidebar menu, navigate to Properties.
-
Click the Select an object dropdown menu, then select [Object] properties to create a property for that object.
- Enter the basic details for your property, then click the Field type tab.
- To build a custom or time between equation, select Calculation as the field type. Click the Calculated property type dropdown menu and select the type of formula you want to create:
- Custom equation: calculate values based on a custom equation. Learn more about creating this type of calculation property.
-
- Time between: calculate values based on the time between two date picker properties within the same object. Learn more about creating this type of calculation property.
- To create a property that calculates the min, max, count, sum, or average, select Rollup. Click the Rollup type dropdown menu and select the type of formula you want to create. Learn more about creating these types of properties.
Calculate values based on properties of associated records
You can create properties for an object that will be calculated based on certain property values of that object's associated records. You can calculate based on all associated records of that object or for specific association labels, including same object associations.
For example, you can create a deal property that counts the total number of sales activities logged for a deal's associated contacts with the Decision maker label.
- Click the Rollup type dropdown menu and select one of the following types:
- Min: displays the minimum value for the selected number property on associated records of the selected object.
- Max: displays the maximum value for the selected number property on all associated records of the selected object.
- Count: counts the total number of associated records of the selected object that have a value for the number property selected.
- Sum: sums up the values for the selected number property on all associated records of the selected object.
- Average: calculates the average of the values for the selected number property on all associated records of the selected object.
- To choose how to format the property's values, click the Number format dropdown menu, then select from the following formats: Formatted Number, Unformatted number, Currency, Percentage, or Duration.
- If you select Currency as the format for a deal property, the property will use your account's Company currency by default. To use each deal record's currency, select the Use record currency instead of company currency checkbox.
Please note: using a record currency only affects how the value is displayed, and will not automatically apply an exchange rate.
- Select the associated object and associated record property to calculate the property based on.
- To calculate based only on records with a specific label, click Select association labels, then select the labels you want to include.
- To add an additional condition, click Create condition. When an additional condition is set up, that condition must be met in order for the property to be calculated (e.g., calculate the property when Recent deal amount > 1000).
- In the first dropdown menu, select a property.
- In the second dropdown menu, select an operator that will compare the first property's value to a number or to another property's value.
- In the third dropdown menu, select a property or enter a number that will be compared to the first property.
- Click Create. Once created, the property's displayed field type will be Rollup.
Calculate values based on time between two properties
You can create properties that calculate the time between two selected date picker properties within the same object. For example, you can calculate the time between when a ticket's owner was assigned and when the ticket was closed. Learn more about how Time Between calculation property values are displayed.
Please note: if you're trying to build a property based on today's date, it's recommended to use relative time filters for date properties in views, lists, reports, or workflows rather than create a time between calculation property. For example, you can include contacts in a list if Last engagement date is more than 7 days ago, or enroll deals in a workflow when Contract renewal date is less than 31 days from now.
- Click the Calculated property type dropdown menu and select Time between.
- Click the dropdown menus to select your Start date and End date properties.
- To add an additional condition, click Create condition. When an additional condition is set up, that condition must be met in order for the property to be calculated (e.g., calculate the property when Recent deal amount > 1000).
- In the first dropdown menu, select a property.
- In the second dropdown menu, select an operator that will compare the first property's value to a number or to another property's value.
- In the third dropdown menu, select a property or enter a number that will be compared to the first property.
- Click Create. Once created, the property's displayed field type will be Calculation.
The following behavior is expected when displaying values for time between calculation properties:
- The time will be displayed differently in different HubSpot tools.
- For date properties without a timestamp, the default time used in the calculation will be 12:00 am UTC for the selected day.
- On a record (e.g., a contact record), the displayed value will be in hours, days, months, or years, and will be rounded up to the next unit based on specific thresholds. For example, if the time calculated is one month and twenty days, then the value displayed will be One month, but if the time calculated is one month and twenty-seven days, then the value displayed will be Two months. The thresholds are:
- 45 seconds or more rounds up to one minute
- 45 minutes or more rounds up to one hour
- 22 hours or more rounds up to one day
- 26 days or more rounds up to one month
- 11 months or more rounds up to one year
- In custom reports that use a property with this field type, the displayed value will be in days. For example, if the time calculated is one year and twenty days, then the value displayed will be 385 days.
Please note: within HubSpot, the raw values of Time between and Average property types are stored in milliseconds. If an equation with these values yields a higher value than expected, use a millisecond converter to convert to your desired unit of time.
Calculate values based on a custom equation
You can also create properties that calculate values based on your own criteria. Custom equations can only be set up for number properties within the same object for which you're creating the new property. For example, you can create an equation to calculate the amount from a company's most recent deal (Most recent deal amount) compared to how many times your business contacted the company (Number of times contacted).
You can build your custom equation with arithmetic operators, comparison operators, logic operators, conditional statements, and other functions. These equations can return number, boolean, string, or date values. Learn more about the available operators and functions, and how to format your formulas.
To build a custom equation calculation property:
- Click the Calculated property type dropdown menu, then select Custom equation.
- Click the Output type dropdown, then select the type of output your calculation will return. You can select one of the following: Number, Boolean, String, or Date.
Please note: the selected output type must match the output type shown in the top right of the editor or you'll be unable to create the property. For properties returning a date, you can use either the number or date output type which determines how values are displayed (i.e. number displays date in milliseconds, date displays formatted date).
- If you've selected the Number output type:
- Click the Number format dropdown menu, then select how to format the property's values. You can select one of the following: Formatted Number, Unformatted number, Currency, Percentage, or Duration.
- If you select Currency as the number format for a deal property, the property will use your account's Company currency by default. To use each deal record's currency, select the Use record currency instead of company currency checkbox.
Please note: using a record currency only affects how the value is displayed, and will not automatically apply an exchange rate. To add an exchange rate, you can include the exchange_rate
or dated_exchange_rate
functions in your equation.
- In the editor, insert, type, or paste functions and properties to build your custom equation. Learn more about custom calculation equation syntax. To insert formula elements:
- Click the Insert dropdown menu.
- To insert functions into your equation, select Functions, then select a function.
- To insert properties into your equation, select Properties, then select a property. You can only create custom equations using properties of the same object for which you're creating the property.
- If your equation has errors, click [x] issues above the editor to view the reasons for the errors. You'll be unable to create the property if your equation has unresolved errors. Learn more about how to format your equations.
- To preview the output of your formula, click Test formula.
Please note: if any of the number properties in a custom equation have no value, or a null value, the calculation will not run and the calculation property value will be empty. The value will be empty even if there is a constant number included in the equation. In this situation, can use the if
and is_known
functions to set the value to 0 instead.
- Click Create. Once created, the property's displayed field type will be Calculation.
Custom equation syntax
In the formula editor, you can build your own custom equations using literal data, data from other properties, operators, and functions. Below, learn about the syntax for writing custom calculation equations and review examples of commonly used formulas.
Literal syntax
Using literal data, you can add strings of text, numbers, and true or false values to your equations. You can format strings, numbers, boolean, and date constants in the following ways:
-
String literal: text surrounded by quotation marks. These can be represented with either single quotes (
'constant'
) or double quotes ("constant"
). -
Number literal: numbers without quotation marks. Constant numbers can be any real numbers, and can include point notation. For example, both
1005
and1.5589
are valid constant numbers. -
Boolean literal: constant booleans can be
true
orfalse
. - Date literal: a date in milliseconds. For example,
1698508800000
.
Property syntax
You can include other properties of the same object in your custom equation. If a property is inserted into the editor, it is automatically formatted and validated as part of an equation.
If you choose to manually type or paste a property into the editor, it should be formatted as [properties.{propertyInternalName}]
. For example, to add the property Test score, which has an internal value of Test_score, you'd type it into the editor as [properties.Test_score]
.
When using enumeration properties in an equation (e.g., dropdown select, radio select):
- Values are considered strings, so must be wrapped in double quotes. For example,
"subscriber"
. - You must use the internal name of the property options. For example,
"appointmentscheduled"
.
Operators
You can use operators in your equation to update, evaluate, or compare constants and property values. When using multiple operators, they follow the PEMDAS order of operations. Depending on the type of data you're using, you can include the following operators in your custom equations.
Operator | Description |
+ |
Add numbers or strings. Returns a number. |
- |
Subtract numbers. Returns a number. |
* |
Multiply numbers. Returns a number. |
/ |
Divide numbers. Returns a number. |
< |
Checks if a value is less than another. Supported by number properties or constants. Returns a boolean. |
> |
Checks if a value is greater than another. Supported by number properties or constants. Returns a boolean. |
<= |
Checks if a value is less than or equal to another. Supported by number properties or constants. Returns a boolean. |
>= |
Checks if a value is greater than or equal to another. Supported by number properties or constants. Returns a boolean. |
! |
Checks if none of the values are true. Returns a boolean. |
= or == |
Checks if a value is equal to another. Supported by numbers and strings. Returns a boolean. |
!= |
Checks if a value is not equal to another. Supported by numbers and strings. Returns a boolean. |
or or || |
Checks if either of two values are true. Returns a boolean. |
and or && |
Checks if both values are true. Returns a boolean. |
Functions
You can use functions within custom formulas to calculate values and complete actions with your data. Depending on the type of data you're using, you can include the following functions in your custom equations.
Function | Arguments | Examples |
Get the absolute value of numbers. Returns a number. |
number: the number for which you want to get the absolute value. |
|
Combine up to 100 strings into one value. Returns a string. |
arg1: the string to which arg 2 will be appended. arg2: the string to append to arg 1. |
|
Filter strings that contain a specific sequence of characters. Returns a string. |
property: the property whose values you want to check for the text. text: the sequence of characters that the values should contain. |
|
Get the number of decimal places for a currency. Returns a number. |
currency: the currency string for which you want to calculate the number of decimal places. |
|
Get the value of an exchange rate at the given time. Returns a number. |
currency: the currency string for which you want to calculate the exchange rate on a specific date (e.g., date: the datetime property for which you want to calculate the exchange rate. |
|
Get the most recent exchange rate. Returns a number. |
currency: the currency string for which you want to calculate the exchange rate. |
|
Set up a conditional expression. |
condition: the boolean statement that determines what the calculated value will be. arg2: a boolean, number, or string that will be the calculated value if the condition is met. arg3 (optional): the calculated value if the condition is not met. If included, it must be the same type as |
|
Determine if a value is known for the token. Returns a boolean. |
property: the property you want to check for a value. |
|
Get the date of when the token was last updated. Returns a timestamp in milliseconds as a string. |
property: the property for which you want to check the most recent update date. |
|
Change all characters to lowercase. Returns a string. |
text: the string or text property with values you want to change to lowercase. |
|
Get the maximum of two numbers. Returns a number. |
arg1: the first number or number property. arg2: the second number or number property. |
|
Get the minimum of two numbers. Returns a number. |
arg1: the first number or number property. arg2: the second number or number property. |
|
Get the numeric month of a given date. Returns a number. |
date: the datetime property for which you want to calculate the month. |
|
Convert a number to a string. Returns a string. |
number_to_convert: the number or number property you want to change to a string. |
|
Get the probability of a pipeline stage. Returns a number. |
pipeline: the name of the pipeline for which you want to calculate the probability. |
|
Raise a number to the value of another number. Returns a number. |
base: the base number. exponent: the value to raise the base to. |
|
Round a number down to a specified precision. Returns a number. |
number_to_round: the number or number property you want to round down. precision: the number of decimal places to round down to. |
|
Round a number to a specified precision. Returns a number. |
number_to_round: the number or number property whose values you want to round. precision: the number of decimal places to round to. |
|
Round a number up to a specified precision. Returns a number. |
number_to_round: the number or number property whose values you want to round up. precision: the number of decimal places to round up to. |
|
Get the square root of a number. Returns a number. |
number: the number for which you want to get the square root. |
|
Filter strings that begin with a specific sequence of characters. Returns a string. |
property: the property whose values you want to check for beginning characters. text: the sequence of characters that the values should begin with. |
|
Convert a string to a number. Returns a number. |
string_to_convert: the string or text property whose values you want to convert to a number. |
|
Get the time difference between two dates. Returns a number. |
date1: the starting datetime property. date2: the end datetime property. |
|
Change all characters to uppercase. Returns a number. |
text: the string or text property you want to change to uppercase. |
|
Get the numeric year of a given date. Returns a number. |
date: the datetime property for which you want to calculate the year. |
|
Examples
The following are example formulas based on common use cases.
- You can set up if else statements, including statements with multiple conditions and within functions:
if([properties.number] < 4, "less than four", "more than four")
if([properties.number] < 4, if([properties.other_number] < 2, "both true", "one true"), "not true")
concatenate(if([properties.number] < 4, "less", "more"), " than four")
- When using number properties in a custom formula, you can include the
if
andis_known
functions to set the value to 0 when the number property is empty. For example,if(is_known([properties.number]), [properties.number], 0)
. - When using a record currency in a formula, to add an exchange rate, you can include the
exchange_rate
ordated_exchange_rate
functions in your equation. For example,[properties.amount] * exchange_rate('CAD')
.