Formula Cheat Sheet & Guide

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: 

Formula-Editor-Start

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
operations-auto-suggest

Auto-suggest for Attributes

attributes-auto-suggest

💡  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?" 

Formula-Editor-Validate

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. 

Formula-Editor-test-attributes

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: 

  1. Check or change the data for each attribute so that you can test the outcome
  2. Click "Run"
  3. 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.

  1. ADD_DAYS - Add days to a date
  2. ADD_MONTHS - Add months to a date
  3. ADD_YEARS - Add years to a date
  4. AND - Test multiple conditions
  5. AVERAGE - Find the average in a numerical dataset
  6. CONCAT - Concatenate multiple values
  7. CONTAINS_ALL - Determine if all of a set of values is found within another set. 
  8. CONTAINS_ANY - Determines if any of a set of values is found within another set. 
  9. COUNTIF - Count the number of occurrences of a value in a string
  10. DATE_FORMAT - Change the data format
  11. DECIMAL_FORMAT - Change the decimal format
  12. DIVIDE - Divide one number by another
  13. DLOOKUP - Replace values from a dictionary
  14. EQ - Verify that two values are equal
  15. ESCAPEHTML - Remove all HTML tags from a text
  16. ESCAPESTYLE - Remove all styling from a text
  17. FILTER - Return a list of items that achieve certain conditions
  18. FIND - Identify the first position of a string found in a text (case sensitive)
  19. GT - Strictly greater than
  20. GTE - Greater than or equal to
  21. IF - Return a value based on a set of conditions
  22. IFBLANK - Return a specified value if blank or not
  23. IFERROR -  Return a specified value if error or not
  24. IFNULL - Return a specified value if null or not
  25. IS_SUBSTR - Test if a string is found in a particular text
  26. ISBLANK - Test if a value or field is empty
  27. JOIN - Concatenate values with a delimiter
  28. LEN - Count the characters in a string
  29. LOWER - Convert a string of text to all lowercase
  30. LT - Strictly less than
  31. LTE - Less than or equal to
  32. MAP - Apply an operation to a list of inputs
  33. MAX - Find the maximum value in a numerical dataset
  34. MIN - Find the minimum value in a numerical dataset
  35. MINUS - Subtract one number from another
  36. MROUND - Round a number to the nearest integer multiple
  37. MULTIPLY - Return the product of two numbers
  38. NE - Not equal
  39. NOT - Returns the opposite of the provided logical value
  40. OR - Test multiple condition options
  41. PROPER - Capitalize the first letter in each word of a text
  42. REPLACE - Replace part of a particular string with a different string
  43. ROUND - Round a number to a specified decimal place
  44. RSUBSTITUTE - Replace the last occurrence of a string in a text
  45. SEARCH - Find the first position of a string found in a text (not case sensitive)
  46. SUB_DAYS - Subtract days from a date
  47. SUB_MONTHS - Subtract months from a date
  48. SUB_YEARS - Subtract years from a date
  49. SUBSTITUTE - Replace existing text with a new text in a string (case sensitive)
  50. SUM - Add a set of numbers together
  51. TRIM - Remove all spaces in a text string, leaving just a single space between words
  52. UPPER - Converts a string to all UPPERCASE

 

What's Next

 

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 👇