STOCK INVESTOR PRO > October 2012

# Combining Two Expressions In One Custom Field

Custom fields allow Stock Investor Pro users to go beyond the thousands of data points available for each company by creating their own. These custom fields can then be used for screening as well as creating custom views and reports. The previous installment of SI News gave an introduction to the Custom Field Editor and discussed three expressions: growth rate (GrowthRate[x], [y], [z]), in-line if (IIF[x], [y], [z]) and is field null (IsFieldNull([x])). This installment of SI News continues the conversation on the Custom Field Editor by describing how to combine multiple expressions.

### Breaking Down the Steps

For this example, we calculate a custom field that adds together cash and short-term investments for the latest fiscal quarter and divides the sum by the average number of shares outstanding for the latest fiscal quarter. However, many companies do not report short-term investments or cash separately on their balance sheets, and some do not have these items. Therefore, a company may have a null value for either one or both of these fields—rendering the entire custom field null.

When calculating a multivariate expression, it is a good idea to view it in parts. Breaking it down into more manageable pieces increases the odds of generating a valid expression. (Note that you could also create separate custom fields and then combine them into one “master” custom field. However, our example arrives at the same final figure and is less time-consuming.)

For this custom field, several calculations are taking place:

• Identify whether the cash or short-term investments fields have null values;
• Return a zero value if the cash or short-term investments field is zero, otherwise return the actual field values;
• Sum the values (zero or actual value) of cash and short-term investments; and
• Divide the total by the average number of shares outstanding.

The completed formula is:

(IIF(IsFieldNull([Cash Q1])=0,0,[Cash Q1]) + IIF(IsFieldNull([Short-term investments Q1])=0,0,[Short-term investments Q1]))/[Shares Average Q1]

### Substituting Zeros for Nulls

To create this custom field, we must open the Custom Field Editor and look at the “to-do” list above. [Open the Custom Field Editor by selecting Custom Field Editor from the Tools menu (Tools-Custom Field Editor), clicking on the Custom Field Editor icon from the toolbar or using the Alt+C key command.] The first step is to substitute zeros for null values in the cash Q1 and short-term investments fields. This involves using two IIF() and two IsFieldNull expressions in this custom field.

We verify whether cash Q1 is a null value using the IsFieldNull expression. Select the IsFieldNull() function from the pull-down menu that is right above the “Add Function” button on the right side. After selecting it from the list, IsFieldNull should appear in the area just above the “Add Function” button. If so, click on the “Add Function” button so that IsFieldNull() now appears in the Expression area of the Custom Field Editor. Next, make sure that the cursor is positioned between the parentheses () in the function. Then, scroll down the list of data categories until you come to Balance Sheet - Quarterly and click on the “+” sign next to it. This will expand this data category so that you can see all the individual data fields that make up the category. Scroll down the list of data fields until you come to Cash Q1 and double-click on it. This data field should appear in the expression area (clicking once on Cash Q1 and then clicking on the Add Field button will produce the same result).

Staying with the Cash Q1 data field, we want to create a function that will return a zero value if Cash Q1 is null or return the actual cash amount if the field is not null. This involves using the IIF() expression.

Position the cursor before the IsFieldNull expression in the Expression area of the Custom Field Editor. Select the IIF() function from the pull-down menu that is right above the “Add Function” button. After selecting it from the list, IIF() should appear in the area just above the “Add Function” button. If so, click on the “Add Function” button so that IIF() now appears in the Expression area of the Custom Field Editor. The IsFieldNull expression we just created needs to be inside the IIF parentheses, so the easiest thing to do is to delete the () following IIF and then enclose the IsFieldNull expression with another set of parentheses. This is important, otherwise the formula will come back as invalid. At this point, the custom field should appear as it does in Figure 1.

The logical expression [x] in this statement is whether or not Cash Q1 is null (the IsFieldNull expression returns a zero value). Therefore, the next step is to set the IsFieldNull expression to zero by adding =0 after ([Cash Q1]), as shown in Figure 2.

If Cash Q1 is null (the IsFieldNull field’s value is zero), the IIF field should return a zero value. So we add ,0 to take care of the [y] element of the expression, as shown in Figure 3. When using an IsFieldNull expression and the field is not null, a value of one is returned by the field. Therefore, if Cash Q1 is not null the expression IsFieldNull[(Cash Q1])=0 is not true. Therefore, we want the IIF statement to return the actual value of Cash Q1. To achieve this, we add ,[Cash Q1] to the end of the expression.

### Finishing the Field

The next step is to add to this expression a similar IIF statement using short-term investments Q1, which is also in the Balance Sheet - Quarterly data category.

To complete the field, we enclose the two IIF statements in a final set of parentheses and divide the expression by Shares Average Q1 (Share Statistics data category) to arrive at the completed field in Figure 4.

### Final Touches

As we explained in our introduction to the Custom Field Editor, once you have entered in the full expression, you will want to verify that it is mathematically correct by clicking the Verify button. If the program is able to understand the expression, a box pops up saying the field is valid. The next step is to name and save the new field and then you are asked whether you want this field calculated for all the companies in the database.