# 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.

1. 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.

1. 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.

1. Add the generate unique ID box

2. 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.

2. 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:

2. Define a column which your condition is based on

3. Add the condition into the text box

5. Input the level of discount you want to apply

6. Define what should happen if a product from your current column does not contain a number

### 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.

1. Add the discount percentage box

2. Define your old price (original value)

3. Define your new price (new value)

4. Define how many decimal places you wish the percentage to be calculated to, under round precision

## 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:

1. Add the numeric compare box

2. Select your first column for the comparison

3. Select the operator you wish to use in the comparison from the drop-down menu

4. Select your second column for the comparison

5. Define the value to be assigned when the comparison is a match under the handle match field

6. Define how to handle no match

## Rounding numbers

You can round numbers using the round numeric values box:

1. Add the round numeric values box

2. Define how many decimal places you want to calculate the percentage at under round precision

3. 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.

2. Use the operator drop-down menu to select whether you would like to add, subtract, multiply, or divide a value from the current column

3. Select a column from the drop-down or add a static value that you wish to use to perform the above operation you chose

4. Define how many decimal places you wish the percentage to be calculated to, under round precision

5. 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

6. 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.

1. Add the column math box

2. Use the operator drop-down menu to select whether you would like to add, subtract, multiply, or divide from the current column

3. Select a column from the drop-down or add a static value

4. Select another column from the drop-down or add another static value

5. 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).

1. Add the math template box

2. Define up to three extra columns to use in your calculation

3. 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

4. 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

Output: 11

1. Add the in-row math box

2. Define the delimiter for how your values are separated in the cell

3. Define the operator - whether the values should be added or multiplied