Work with numbers and math functions
Work with numbers and math functions in Productsup.
You may wish to do calculations based on numbers you have in the platform, such as creating discounts, using formulas to calculate ROAS, or otherwise manipulating your numeric data. You may even wish to create random numbers.
There are a number of boxes that can help you achieve this.
Note
When working with numbers, you must ensure that they are valid numbers (either integers or floats) and do not contain any text elements such as commas. Consider using the make valid price box to normalize them. See Make prices valid and convert strings to integers.
Generating random numbers
To generate a random number in a column, you can add the generate random number box.
Add the generate random number box
Generating MD5 hashes
If you want to generate a unique and encrypted MD5 hash for your input data for that column, you can add the generate MD5 hash box.
Add the generate MD5 hash box
Generating unique IDs
You can also create a unique ID for each product using the generate unique ID box. This generates the same ID for all products with the same input in the column.
Alternatively, you can input columns that the box should check for uniqueness when generating the ID.
Add the generate unique ID box
Optionally, you can define columns (newline-separated) for which the box should group products by, creating a unique ID for each unique group
You can also consider using the unique ID generator service to achieve the same effect.
Adding VAT to prices
To add VAT to your prices, you can use the add VAT box:
Add the add VAT box
Define how much your VAT should be
Calculating Discounts
You can use boxes to calculate prices based on a set discount or to calculate the percentage of discount between a price and a sale price.
Calculating discounted prices
To calculate prices based on a set discount and your products meeting a condition, consider using the discount box:
Add the discount box
Define a column which your condition is based on
Add the condition into the text box
Add another optional condition
Input the level of discount you want to apply
Define what should happen if a product from your current column does not contain a number

Note
If you want to apply a discount to all products, you can add your mandatory condition to be: price > 0.
Calculating the percentage of the discount
If you have two prices and want to calculate the percentage of discount between them, you can use the discount percentage box. This could be useful for calculating the current percentage from a price and a sale price.
Add the discount percentage box
Define your old price (original value)
Define your new price (new value)
Define how many decimal places you wish the percentage to be calculated to, under round precision
Optionally add text before or text after your calculated percentage

Comparing numbers from two columns
If you wish to compare the numbers in two columns and assign a value based on the outcome of the comparison, you can do so using the numeric compare box:
Add the numeric compare box
Select your first column for the comparison
Select the operator you wish to use in the comparison from the drop-down menu
Select your second column for the comparison
Define the value to be assigned when the comparison is a match under the handle match field
Define how to handle no match

Rounding numbers
You can round numbers using the round numeric values box:
Add the round numeric values box
Define how many decimal places you want to calculate the percentage at under round precision
Select what should happen if your current input is not a valid number
Performing mathematics calculations
Math
You can perform a calculation with the current column, which involves either a static value or the values from another column, by using the math box.
Add the math box
Use the operator drop-down menu to select whether you would like to add, subtract, multiply, or divide a value from the current column
Select a column from the drop-down or add a static value that you wish to use to perform the above operation you chose
Define how many decimal places you wish the percentage to be calculated to, under round precision
Choose the round method and whether you want to round normally, round up, or round down
if you leave the round precision field empty, this will have no effect on the outcome
Define what should happen if your input data is not a valid number
In the below example, we are taking our current input data, adding 4 to it, and are not rounding it.

Column Math
You can also perform calculations using multiple columns, by adding the column math box.
Add the column math box
Use the operator drop-down menu to select whether you would like to add, subtract, multiply, or divide from the current column
Select a column from the drop-down or add a static value
Select another column from the drop-down or add another static value
Define how many decimal places you wish the percentage to be calculated to, under round precision
Tip
The calculation between the first column or static value and the second column or static value will first be carried out. After this has been done, the calculation between the input data and this newly calculated value will be carried out.
In the following example, you are adding 20 to the price column, before adding this calculated value to the current input data from the column.

Math Template
For the most flexibility, you can define your own calculations using a formula by using the math template box. You can use up to four columns here (including the current input column).
Add the math template box
Define up to three extra columns to use in your calculation
Enter a valid twig template for your calculation
the twig should start and end with curly brackets and whitespace: {{ calculation }}
you can refer to the current value in the column using: value
Define how many decimal places you wish the percentage to be calculated to, under round precision

You can create complex formulae using the twig templates. The below example takes the current input value and divides it by the value in column1, before multiplying the result by 45 and then adding the value from column2:
{{ (value / column1) * 45 + column2 }} |
In-row Math
The in-row math box can be used to add or multiply the values in one column per product.
For example:
Input: 1,4,6
Operator: add
Output: 11
Add the in-row math box
Define the delimiter for how your values are separated in the cell
Define the operator - whether the values should be added or multiplied