Formula Cheat Sheet & Guide

How to write formulas for Computed Attributes

Computed Attributes help you transform your attribute outputs for Channels and Brand Portals. 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
  • <html> - Elements of HTML can be used in formulas in combination with operations to change the style of an attribute value, for example to add bullets or line breaks.

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.

ℹī¸ Note that, when referencing multiselect attributes, the output result will contain brackets "[ ]". To remove brackets from the output, use a JOIN operation before referencing your multiselect attribute in the formula, following this format: JOIN($YOUR_ATTRIBUTE, "your_separator").

Here's an example using a multiselect attribute in a CONCAT operation:

CONCAT($ATT.ATTRIBUTE, " ", JOIN($ATT.MULTISELECT, ","))

 

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

What's next?

 

Is there anything you were hoping to find in this article that is missing? Did this article answer the questions you had? Let us know in our Help Center feedback form! 🙌

 

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 👇