## How to write formulas for Computed Attributes

Computed Attributes help you transform your attribute outputs for Channels, E-Catalogs, and PDF Templates. In this guide, you will learn how to use the formula editor, and what operations are available.

### How to use the Formula Editor

After you have created your Computed Attribute, you can start editing the formula by clicking on the options icon next to the attribute you want to configure.

Once you have done this, you should see this screen slide out from the right side of the page:

In the Formula Editor, you will see a text box. This is where you write your formulas using the available operations, your existing attributes, and text inputs.

Formula syntax, or how a valid formula is written, is **based largely on Excel**, Google Sheets, and Python.

**How to write a formula**

- Use operations
- Enclose operations in parentheses
- Insert
**properties**using the "$" symbol - Insert
**line breaks**using CTRL+Enter enclosed in "quotes"

**Other Formula Elements:**

**$$ITEM -**This is used to represent a value of a Multiselect attribute. This is used in operations like MAP and FILTER as a placeholder variable that will take the different values of the attribute in a loop execution.**[Brackets]**- These are used in formulas like JOIN or DLOOKUP to represent a set or range of values

The formula editor will help you with autosuggest for both operations and attributes. For **operations**, start typing the name of the operation you want to use. For **attributes**, start by typing "$" then the attribute list will appear.

**Auto-suggest for Operations**

**Auto-suggest for Attributes**

đĄ When searching for your own attributes, just type $ and then the name of your attribute. You do not need to use the ATT prefix.

**How to validate a formula**

When you validate a formula, you are asking the system, "Is this formula written correctly?", "Do you understand this?"

To validate a formula, once you are finished editing, click **"Validate".**

Then, one of two things will happen. Either you will **get an error**, explaining why the formula isn't correctly written, or you will **see the attribute testing area below the Formula Editor**

âšī¸ You can also click **"Test and Apply"** in the top right corner to validate the formula and close the window.

#### How to test formula attributes

If your formula has been validated, then you will see this area appear below the Formula Editor, and the Editor will be disabled.

This area lets you test different possible inputs for your Computed Attribute to make sure your formula gives you the correct results.

Attributes without fixed inputs, like numbers or texts, will have dummy data presented, while those with fixed inputs like multi-select or dropdown, will show your existing inputs.

**To test attributes: **

- Check or change the data for each attribute so that you can test the outcome
- Click
**"Run"** - Check the result at the bottom of the testing area and repeat the process as needed

### List of Operations

Here are all the available operations listed in **alphabetical order**. Click each link to take you to the operations page in a new tab where you can see the definition, syntax, and examples.

**ADD_DAYS -**Add days to a date**ADD_MONTHS -**Add months to a date**ADD_YEARS -**Add years to a date**AND -**Test multiple conditions**AVERAGE -**Find the average in a numerical dataset**CONCAT -**Concatenate multiple values**CONTAINS_ALL -**Determine if all of a set of values is found within another set.**CONTAINS_ANY -**Determines if any of a set of values is found within another set.**COUNTIF -**Count the number of occurrences of a value in a string**DATE_FORMAT -**Change the data format**DECIMAL_FORMAT -**Change the decimal format**DIVIDE -**Divide one number by another**DLOOKUP -**Replace values from a dictionary**EQ -**Verify that two values are equal**ESCAPEHTML -**Remove all HTML tags from a text**ESCAPESTYLE -**Remove all styling from a text**FILTER -**Return a list of items that achieve certain conditions**FIND -**Identify the first position of a string found in a text (case sensitive)**GT -**Strictly greater than**GTE -**Greater than or equal to**IF -**Return a value based on a set of conditions**IFBLANK -**Return a specified value if blank or not**IFERROR -**Return a specified value if error or not**IFNULL -**Return a specified value if null or not**IS_SUBSTR -**Test if a string is found in a particular text**ISBLANK -**Test if a value or field is empty**JOIN -**Concatenate values with a delimiter**LEN -**Count the characters in a string**LOWER -**Convert a string of text to all lowercase**LT -**Strictly less than**LTE -**Less than or equal to**MAP -**Apply an operation to a list of inputs**MAX -**Find the maximum value in a numerical dataset**MIN -**Find the minimum value in a numerical dataset**MINUS -**Subtract one number from another**MROUND -**Round a number to the nearest integer multiple**MULTIPLY -**Return the product of two numbers**NE -**Not equal**NOT -**Returns the opposite of the provided logical value**OR -**Test multiple condition options**PROPER -**Capitalize the first letter in each word of a text**REPLACE -**Replace part of a particular string with a different string**ROUND -**Round a number to a specified decimal place**RSUBSTITUTE -**Replace the last occurrence of a string in a text**SEARCH -**Find the first position of a string found in a text (not case sensitive)**SUB_DAYS -**Subtract days from a date**SUB_MONTHS -**Subtract months from a date**SUB_YEARS -**Subtract years from a date**SUBSTITUTE -**Replace existing text with a new text in a string (case sensitive)**SUM -**Add a set of numbers together**TRIM -**Remove all spaces in a text string, leaving just a single space between words**UPPER -**Converts a string to all UPPERCASE

### What's Next

- Learn more about attribute types
- Find out how to set up a feed for Google Merchant Center

If you have any questions just click on the chat box in the bottom-right corner and we'll be happy to answer them...

and please let us know đ