Set a value based on an "if" condition

Use a box to set a value based on an "if" condition in Productsup.

Often you may wish to dynamically set a value or another column based on the fulfillment of a condition. There are a number of boxes that can help you with this.

Note

If you are working with prices, you must ensure that these 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.

If you are selecting data from another column to work with, please be aware that the data comes from the stage before the stage you are working on: a rule set on the intermediate stage will draw the values from the import stage.

Adding a static value if another column meets a condition

If you want to set a value if another column meets a condition (such as including a certain phrase), then you can use one of the following options:

The Set Value if Contains box

If another column contains a phrase/value, you can overwrite or append your data with a static value by using the Set Value if Contains box.

  1. Add the Set Value if Contains box

  2. Input the source column you wish to search

  3. Input the phrase you wish to search for and select the method to search for (contains, contains not, etc.)

  4. Choose the method for replacing your current values if there is a match and input the value to be assigned

  5. Select what should occur if there is no match

For the below example, we search the description column to see if it contains PLANET EXPRESS and if there is a match, we append the word PROMOTED to our column. If there is no match, we leave our original data unchanged.

value_if_contains.png

The Set Value if Column Contains box

This has a very similar function to the above box, yet you can add multiple conditions easily with one line per condition.

  1. Add the set value if column contains box

  2. Input the column you wish to search

  3. Input the phrase you wish to search for followed by a colon

  4. Enter the value to be set directly after the colon

  5. Select the mode for which the value should be set

  6. Define whether the match is broad or exact

    • broad: the search term has to simply be included in the input in the search column

    • exact: the search term has to exactly match the entire input in the search column

  7. Define whether only the first match or all matches of your search term should be replaced

For the below example, we search the description column to see if it contains PLANET EXPRESS and if there is a match, we append the word PROMOTED to our column. This only occurs for the first match, all the rest remain unchanged.

value_if_column_contains.png

The Set Value If Value In box

The set value if value in box overwrites the input in your column if a match is found. You can add as many conditions as necessary with each condition separated by a newline.

  1. Add the set value if value in box

  2. Input the source column you wish to search

  3. Define whether the match is broad or exact

    • broad: the search term has to simply be included in the input in the search column

    • exact: the search term has to exactly match the entire input in the search column

  4. Input the phrase you wish to overwrite your data with if there is a match

  5. Enter the value(s) to search for in the text field

    • one value should be added per line

set_value_if_value_in.png

The Set Value If Value Not In box

The set value if value not in box works in a similar manner to the set value if value in box, yet only overwrites your data if your search value is not found.

Adding or appending a column if another column meets a condition

If another column contains a phrase/value, you can overwrite or append your data with a column by using the set column if contains box.

  1. Add the set column if contains box

  2. Input the source column you wish to search

  3. Input the phrase you wish to search for and select the method to search for (contains, contains not, etc.)

  4. Select the column with which you want to overwrite/append your data with

  5. Select what should occur if there is no match

In the below example, we search the description column, and if it doesn’t contain the phrase Shipping Material, we overwrite our current data with the data from the price column. If there is no match, we will not change our current data.

adding_set_column_if_contains.png

Replacing data if it contains a certain string

With this box you can overwrite your current if it contains a specific string, by using the contains string box.

  1. Add the contains string box

  2. Input the value to search for under the if value contains field

  3. Enter the value to overwrite your data with if there is match, under the set value to field

  4. Optionally, you can define a phrase to set if there is no match, under the otherwise set value to field

In the below example, we search our current data for any occurrence of the phrase Philipp J. Fry. If there is a match, we overwrite our current data with Leela. If there is no match, we overwrite our data with the phrase Why not Zoidberg?.

replace_contains_string.png

Setting a value if the input is greater than a certain value

If the data in your current column is greater than a set threshold, you can assign a value to replace it.

  1. Select the value which your current data should be greater than

  2. Select an output to be returned if this condition is met

  3. Choose from the drop-down how you want to deal with data that doesn’t match your condition

set_value_if_greater_than.png

Setting a value or column if there is no data (empty column)

If your current data is empty, then you can overwrite this empty value with either a value or a column, by using either the set value if empty or the set column if empty boxes. Although you set this box for the entire column, it will only overwrite products where the data is empty.

  1. Add either the set column if empty or the set value if empty box

  2. Input the value or column (dependent on the box you selected) to overwrite your empty data with

Conditionally set a value if there is no data

Similar to the set value/column if empty boxes, you can set a value if your current data is empty and a condition is fulfilled.

  1. Add either the set value if empty (conditional) box

  2. Select a source column for your condition to be based on

  3. Input the condition which should be fulfilled, for the box to take effect

  4. Input the value to overwrite your empty data with

In the below example, we search first for all products with empty data in our column. Then, we check if the description column contains the phrase Philipp J. Fry. If this condition is met, we replace the value in our current column with the phrase DeliveryBoy approved.

set_value_if_empty_conditional.png

Setting a value or column if there is data (non-empty column)

You can overwrite your current data with either a value or a column if your current data is not empty. This is achieved by using either the set value if not empty or the set column if not empty boxes. Although you set this box for the entire column, it will only overwrite products where the data is not empty.

These boxes do the opposite of the set value/column if empty boxes

Appending the data from another column if the data is not present

You can add the data from another column if it is not included already in your current column, by using the append/prepend column if value not present box.

  1. Select the column you wish to add if the information from it is not already in the current column

  2. Choose the mode: whether you’d like to append or prepend this column

  3. You can optionally define the text to add before or after this column

In the below example, we are checking our current data to see if the data from the brand column is included. If it is not already present, we will append the brand column to our current column, with the static text Brand: before it.

append_prepend_if_not_present.png

Comparing data across columns and setting values based on the outcome

There are a number of boxes which you can use to compare data across columns and overwriting/appending your current data.

The Set Value by Compare box

You can assign or append/prepend a value based on the a comparison condition with another column, by using the set value by compare box.

  1. Select the column for comparison with your current data

  2. Input a condition using the logical operator and a value

  3. Select a value to replace with and whether your current data should be assigned(overwritten)/appended/etc.

In the below example, we check if the data in the availability column for each product is less than 5, overwriting the data in our current column with the phrase out of stock if this condition is met.

set_value_by_compare.png

The Set Value by Column Compare box

Using the set value by column compare box, you can set up to 2 independent conditions that have to be fulfilled in order to assign or append/prepend a value or a column. This is an IF OR condition.

  1. Select the column for comparison with your current data

  2. Input a condition using the logical operator and a value

  3. You can optionally select a second, independent, condition

  4. Select a value to replace with and whether your current data should be assigned(overwritten)/appended/etc.

In the below example, we will overwrite the data in our current column with Buy it now! if:

  • IF EITHER the availability is less than or equal to 5

  • OR the price is greater than or equal to 20

set_value_by_column_compare.png

The Set Value by Column Compare (Multicondition) box

Using the set value by column compare (multicondition) box, you can set 2 connected conditions which both have to be fulfilled in order to assign or append/prepend a value or a column. This is an IF AND condition.

  1. Select the first column for comparison with your current data and select a logical operator

  2. Select the second column for comparison with your current data and select a logical operator

  3. Input the values for the first and the second comparisons into the text field, separated by a colon

  4. Select a value to replace with and whether your current data should be assigned(overwritten)/appended/etc.

In the below example, we will overwrite the data in our current column with Buy it now! if:

  • IF the availability is less than or equal to 5

  • AND the price is greater than or equal to 20

set_value_by_column_compare_multi_condition.png