Administration > Working with the Type and Attribute Management Utility > Managing Types > Type Information Page > Attributes Tab > Creating a New Attribute > Formulas
  
Formulas
Local attributes in PTC FlexPLM that represent either derived string or derived numeric attributes use formulas to derive their values from the values of other attributes. Formulas for derived string and derived numeric attributes can use both attribute and literal values to compute or generate a derived attribute value. Calculated attributes in PTC FlexPLM can only contain a literal numeric constant value.
You can define the expression to evaluate in the Formula field during the Set Properties step of creating the calculated, derived string, or derived numeric attribute, or by editing the Formula field on the attribute information page once the calculated, derived string, or derived numeric attribute has been created.
* 
If an attribute affecting a derived numeric or derived string attribute is modified when creating or editing an object, the formula is not immediately reevaluated. Once the create action or edit action is processed, the formula is reevaluated and the attribute value is updated.
Data Types in Formulas
Only attributes of the following data types are supported in formulas: Derived String, String, Integer Number, Real Number, Boolean, Date and Time, Object Reference, Version Reference, and Hyperlink. The result of the formula must match the specified data type of the derived string or derived numeric attribute, but attributes of different data types can be used within the formula itself.
When attributes of different data types are used within the formula, the system converts the data types to the same data type as required for the operation or function used in the formula, before performing the operation or function. The formula result is in that same data type. The data type conversion is applied in the following priority order:
1. String—if at least one argument in the formula has a data type of String, all arguments are converted to have a data type of String. (Hyperlink, Date and Time, and Derived String are automatically converted to String.)
2. Real Number—if at least one argument in the formula has a data type of Real Number, all arguments are converted to have a data type of Real Number.
3. Integer Number—if at least one argument in the formula has a data type of Integer Number, all arguments are converted to have a data type of Integer Number.
4. Boolean.
For example, in the formula attrA + attrB, if attrA is a String data type and attrB is a Real Number data type, attrB is converted to a String data type and concatenated with attrA. If the value of attrA is Result: and the value of attrB is 1.5, then the result of the formula is Result:1.5.
Similarly, if attrC is an Integer Number data type, and attrD is a Real Number data type, then in the formula attrC * attrD, attrC is converted to a Real Number data type, and the result of the formula is a Real Number data type.
The system validates expressions entered in the Formula field to ensure that the data type result matches the data type of the derived string or derived numeric attribute. If the data type of the evaluated result does not match the data type of the derived string or derived numeric attribute, the formula is not saved. The data type of a formula result can be converted by changing how the formula is specified. In the following, <formula> is the original formula whose data type is being converted.
To convert a formula resulting in a Boolean, Integer Number, or Real Number to a String data type, enter the following in the Formula field:
""+(<formula>)
To convert a formula resulting in a Boolean or Integer Number data type to a Real Number data type, enter the following in the Formula field:
1.0*(<formula>)
To convert a formula resulting in a Boolean data type to an Integer Number data type, enter the following in the Formula field:
1*(<formula>)
Example: Calculating a Numerical Value
Use operators and internal names of attributes to build formulas which calculate the desired attribute value. (You must use the Internal Name of an attribute in formulas, rather than its Display Name.)
For example, if you had a Total Cost attribute, which is meant to be the value of the Quantity attribute multiplied by the value of the Unit Cost attribute, plus the value of the Handling Fee attribute, you could use the following formula to calculate the Total Cost attribute value:
(quantity*unitCost)+fee
Example: Combining Non-Numerical Attribute Values
Formulas can also be used to combine non-numerical attribute values.
For example, if you created a derived string attribute named ID, you could combine the values of the Name and Number attributes of the type as the value of the ID attribute using the following formula:
name+"("+number+")"
This would result in an ID attribute value such as MyDocument(0001A).
Example: Including White Space Between Values
To include white space between values for derived string attributes, include the space between quotes in your formula, as follows:
brand+" "+year
This would result in a value such as Brandname 2014.
Supported Functions
* 
There are no multi-valued functions currently supported for calculated attributes.
The following functions are supported:
Function
Description
isNull( )
Null check
str( )
Convert number to String data type
abs( )
Absolute value or magnitude
avg( )
Average of a list of values
sum( )
Sum of a list of values
min( )
Minimum of a list of values
max( )
Maximum of a list of values
round()
Converts a number with a decimal (real number) into an integer number
When the decimal contains .5, the number is rounded to an even number (for example, 30.5 is rounded down to 30 and 31.5 is rounded up to 32)
When the decimal contains other numbers, the number is rounded to the nearest number (for example, 30.8 is rounded up to 31 and 33.4 is rounded down to 33)
mod()
Returns the remainder of one number divided by another number. (Integer data types, only)
${}
Wraps attribute internal names which include special characters, so they can be used within the formula. All attribute internal names can be wrapped, but attribute internal names which include the dollar sign ($) or square brackets ([ ]) must be wrapped when used in formulas. For example, attributes with internal names of my$attribute or my[very$complex]attribute can be used in a formula when wrapped as follows:
${my$attribute}
${my[very$complex]attribute}
If the attributes used in the Example: Calculating a Numerical Value section had internal names which include special characters, the formula for the Total Cost attribute could appear as follows:(${item$quantity}*${unit$cost})+${handling$fee}
* 
Attributes in PTC FlexPLM cannot contain hyphens, underscores, or periods.
Supported Operators
The following operators are supported:
Operator
Description
+
Addition; can also be used to concatenate strings
-
Subtraction
*
Multiplication
/
Division
( )
Open and closed parentheses, to indicate a different priority in the order of operations (the operations within the parenthesis are to be performed first)
" "
Double quotes, to indicate that the content of the quotes is a literal string. Any non-number not inside double quotes is treated as an attribute name
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
==
Equal to
!=
Not equal
^
Power or exponentiation
&
And
|
Or
~
Not
^*
Exclusive or
&&
And
||
Or
!
Not
? :
Conditional operator, indicating the result if the specified condition is true or false:
(condition) ? value if true : value if false
For example, assume that a type has attributes of length, width, and shape, where shape is a calculated attribute with the following formula:
(length>width) ? "longer" : "wider"
If the value of the length attribute is greater than the value of the width attribute, then the shape attribute is assigned a value of longer. If the value of the length attribute is not greater than the value of the width attribute, then the shape attribute is assigned a value of wider.
%
Remainder