Rule: Calculation#

This rule allows you to perform calculations with variables within the feed. For example, you can calculate prices without VAT, adjust values according to VAT rates, or perform more complex arithmetic operations.

Extra features#

  • The Calculation field supports operations: addition, subtraction, multiplication, division, brackets, and variables
  • Rounding of resulting values (to tenths, hundreds, etc.)

Practical examples#

Example 1: Calculate price without VAT#

This example shows how to use the Calculation rule to remove VAT from a price, for example for the Hungarian Arukereső, where it is a required element.

1. Creating a new rule:

  • Open the “Rules” page.
  • Click the New rule button.

2. Selecting the rule type:

  • In the Rule type field, select the Calculation option.

3. Selecting products:

  • In the Query field, choose either All products or create your own Product query for specific products you want the rule to apply to.

4. Choosing the element to change:

  • In the Element field, select the element where you want to write the calculation result.
  • In our case, this will be the netprice element.

5. Enter the calculation value:

  • In the Calculation field, enter the formula for calculating the price without VAT: %g:price%/1.27
  • This calculation takes the price with VAT and divides it by 1.27 (assuming a 27% VAT rate).

6. Setting the rounding type:

  • In the Rounding type field, select the desired method, for example: up, down, standard, 0, or 0.5.

7. Selecting the rounding level:

  • In the Round to field, choose units, tenths, hundredths, etc., depending on the type of rounding you need.

8. Setting the decimal separator:

  • Choose whether you want to use a comma or period as the decimal separator.

9. Setting the thousands separator:

  • In the Thousands separator field, select the desired separator (space, period, comma, or none).

10. Naming the rule:

  • In the last step, enter the rule name, for example: “Calculate price without VAT”.

Example 2: Increase the price by X%#

This example shows how to use the Calculation rule to increase the price by 15% (for example, for a promotion or margin increase).

1. Creating a new rule:

  • Open the “Rules” page.
  • Click the New rule button.

2. Selecting the rule type:

  • In the Rule type field, select the Calculation option.

3. Selecting products:

  • In the Query field, choose either All products or create your own Product query for specific products you want the rule to apply to.

4. Choosing the element to change:

  • In the Element field, select the element where you want to write the calculation result.
  • In our case, this will be the g:price element.

5. Enter the calculation value:

  • In the Calculation field, enter the formula for increasing the price: %g:price%*1.15
  • This calculation multiplies the price by 1.15, increasing it by 15%.

6. Setting the rounding type:

  • In the Rounding type field, select the desired method, for example: up, down, standard, 0, or 0.5.

7. Selecting the rounding level:

  • In the Round to field, choose units, tenths, hundredths, etc., depending on the type of rounding you need.

8. Setting the decimal separator:

  • Choose whether you want to use a comma or period as the decimal separator.

9. Setting the thousands separator:

  • In the Thousands separator field, select the desired separator (space, period, comma, or none).

10. Naming the rule:

  • In the last step, enter the rule name, for example: “Price increase for Allegro”.

Example 3: Calculate the discount percentage#

This example shows how to use the Calculation rule to determine the percentage discount on a product.

1. Creating a helper element:

  • On the “Elements” page, click the “New element” button in the top right corner.
  • Create a helper element, for example “discount_amount”.
  • Optional: Hide this element using the toggle at the end of the row.

2. Creating a new rule:

  • Open the “Rules” page.
  • Click the New rule button.

3. Selecting the rule type:

  • In the Rule type field, select the Calculation option.

4. Selecting products:

  • In the Query field, choose either All products or create your own Product query for specific products you want the rule to apply to.

5. Choosing the element to change:

  • In the Element field, select the element where you want to write the calculation result.
  • In our case, this will be the discount_amount element.

6. Enter the calculation value:

  • In the Calculation field, enter the formula for calculating the discount: ((%g:price%-%g:sale_price%)/%g:price%)*100
  • This formula calculates the percentage difference between the original and the discounted price.
  • 💡 Tip: If you need to place text after the calculation result, e.g., the % sign (percent) or a currency symbol, you need to create an additional rule of the Overwrite type.

7. Setting the rounding type:

  • In the Rounding type field, select the desired method, for example: up, down, standard, 0, or 0.5.

8. Selecting the rounding level:

  • In the Round to field, choose units, tenths, hundredths, etc., depending on the type of rounding you need.
  • In our case, this will be units.

9. Naming the rule:

  • In the last step, enter the rule name, for example: “Calculate discount amount”.

Additional uses#

  • Increase the price by a partner commission
  • Calculate the VAT rate
  • Calculate the selling price from the purchase price
  • Convert prices to another currency using a dynamic or fixed exchange rate
  • https://www.bidding-fox.cz/elements-sparovanost
  • Calculate the discounted price (often into g:sale price)

FAQ#

What is the Calculation rule for?#

This rule allows you to perform calculations with values in feed elements. You can use it, for example, for:

  • calculating the price without VAT,
  • increasing the price by a percentage or fixed amount,
  • currency conversion,
  • calculating the discount percentage,
  • calculating commissions or margins,
  • calculating the discounted price.

What mathematical operations can I use?#

In the “Calculation” field, you can enter common mathematical operations:

  • addition (+) – e.g., %price%+50,
  • subtraction (-) – e.g., %price%-100,
  • multiplication (*) – e.g., %price%*1.15,
  • division (/) – e.g., %price%/1.21,
  • brackets for defining the order of operations, e.g., (%price%-100)*1.15.

What rounding types can I use?#

In the “Rounding type” field, you can choose:

  • up – always rounds up,
  • down – always rounds down,
  • standard – regular rounding based on the value after the decimal point,
  • to 0 or 0.5 – to the nearest half unit or 0,
  • to 0.9 – rounds to the nearest value ending in “.9”,
  • to 0.99 – rounds to the nearest value ending in “.99”.

How do I choose the rounding level?#

In the “Round to” field, you can set how many places the value should be rounded to:

  • units,
  • tenths,
  • hundredths,
  • hundreds,

depending on the output feed format requirements.

What number format can I set?#

In the “Decimal separator” field, choose whether to use a comma or period (,) / (.). In the “Thousands separator” field, select a space, period, comma, or no separator. 💡 For example: 1,000.50 or 1.000,50 depending on the target format requirements.

What happens if I use a variable that does not exist or does not contain a numeric value?#

Mergado will not evaluate such a variable and will skip the row. In the editor, an unrecognized variable is displayed with a red background. It is recommended to test the calculation on a smaller sample of products using the Rule walkthrough.

Can I include text elements (e.g., currency) in the calculation?#

No. The calculation works only with numeric values. If you want to add text or currency to the result (e.g., “EUR”, “%”), create a subsequent Rewrite rule that adds these characters.

How do I calculate the price without VAT?#

Enter the formula in the “Calculation” field: %g:price%/1.21 (or 1.27 depending on the VAT rate). Save the result, for example, to the netprice element. The rule will calculate the price without VAT from the original price with VAT.

How do I calculate the discount percentage?#

Enter the formula: ((%g:price%-%g:sale_price%)/%g:price%)*100. The result will be the percentage difference between the original and discounted price. 💡 If you need to add the “%” sign, use a subsequent Rewrite rule.

How do I increase the price by a percentage or fixed amount?#

Enter in the “Calculation” field, for example:

  • for a 15% increase → %g:price%*1.15,
  • for a 20 EUR increase → %g:price%+20.

Mergado will automatically recalculate the new value and write it to the selected element.

Can I use the rule for currency conversion?#

Yes. You can include a fixed or dynamic exchange rate in the calculation. For example, for converting from CZK to EUR (1 EUR = 24.50 CZK): %g:price%/24.5. 💡 If you use dynamic rates, it is advisable to load the data from an external file using the Data file import rule or the Bidding Fox Elements extension.

Can I combine multiple operations in the rule?#

Yes. You can include multiple operations in the calculation at once and use brackets to define the order, e.g.: ((%g:price%+50)*1.2)/1.21. Mergado follows the standard mathematical order of operations.

How do I round the calculation result?#

Within the Calculation rule, use the “Rounding type” and “Round to” settings just like in the Round numbers rule. For example: up + to hundredths → 123.456 → 123.46. This allows you to calculate and format results in a single step.

What happens if the calculation contains an error (e.g., division by zero)?#

Mergado will skip the record and keep the original value. When applying rules, Mergado will flag the issue for the given product. We recommend testing calculations on a sample of products using the Rule walkthrough before deployment.

How do I check if the result was calculated correctly?#

After saving and applying the rules or after regenerating the feed, open the product preview or use the Rule walkthrough. You will see how the resulting element value changed and whether it matches the expected calculation.

Can the rule be scheduled to run only at a specific time (e.g., for overnight price recalculation)?#

Yes. Using the Timer, you can specify specific time slots or dates when the rule should be active.

🇨🇿 🇬🇧 🇩🇪 🇭🇺