Using Variables in a Calculated Attribute

Once you have determined that a calculated attribute is a good choice, next consider if one or more variables would be useful. A variable is used to separate each element of the calculation into its own section. For more information on variables, refer to the Variable Functions documentation here.

Note: When the calculation required involves many parts, it is a good idea to start with a small element, test and verify the results, before adding additional elements.

Functional and lengthy calculations without variables are harder to manage and troubleshoot later. To illustrate, the same calculation is written below; both without variables, and with variables.

The version that uses variables makes troubleshooting and maintenance easier for the following reasons:

  • Identifying where a new attribute value should be inserted into the list is more obvious.
  • Finding a missing parenthesis or comma is easier with fewer nested functions.
  • Modifying a single element involves only the few defined lines in a variable, rather than having to first determine where the functions are in the larger calculation.

Example Input

The website requirement includes displaying the following 17 attribute values (when the exist) in a single block, including styling and introductory text to introduce the value.

Example Without Variables

Using the function editor, the following value template is created without variables. Notice that the first concatenate function wraps all of the attributes that should be included in the output. To make a change in one attribute, or the formatting applied, requires locating and changing only the functions for that attribute.

Note that many character tags ([PN], [ST], [FT], etc.) are being used to style the text for output. For more information on tags, refer to the Tags documentation here.

Example With Variables

Using the function editor, the following value template is created and includes variables. Notice that each attribute that should be output is addressed in a single variable at the top. The final concatenate function then calls each of the variables and separates them with a hard return ("\n"). To make a change in one attribute, or to the formatting applied, locate the variable for that attribute.

Example Output

Regardless of the method used to create the value template, the output contains the same static text and values as shown below in the following two resulting attributes.

  • Build All Calculation - shows the result of the calculated attribute created without variables.
  • Build All Calculation with Variables - shows the result of the calculated attribute created using variables.