Desktop User Guides > Professional > Table scripting > Table specification syntax > Special elements > Creating a derived element calculated from other elements
 
Creating a derived element calculated from other elements
Sample Script File: SpecialElements.mrs
This example script is based on the Museum sample data set. See Running the sample table scripts for information on running the example scripts.
age{.., Derived '55 or over' derived('E5564_years + E65_years')}
This example uses a derived element to display a value calculated from the values in two other elements.
Here is a table that has this axis on the side:
This graphic is described in the surrounding text.
Derived elements use an arithmetic expression based on the values of other elements in the table. This differs from the expression() syntax, which uses a logical expression that tests the case data to determine whether a respondent is included in the count.
Expressions in derived elements are calculated only for cell items based on counts, for example count and column percent, not for summary statistic cell items such as mean or stddev. Expressions are not calculated for cell items that display unweighted counts in a weighted table.
Derived element expressions are calculated for all elements, including non-category elements, in rows and columns.
The expression in a derived element can refer only to other elements in the same variable. For example, you cannot define an expression for an element in the interest variable that references the elements of the age variable. Derived elements are displayed only at the innermost nesting level of a table. If a variable includes net elements, the expression in a derived element can refer only to other elements in the same net.
If a table contains both row and column derived elements, the row elements are evaluated before the column elements. This means that the column value is displayed at the intersection of row and column derived elements.
Note for Quantum users
Derived elements provide similar functionality to the m;ex= statement in Quantum. If you are accessing Quanvert data using UNICOM Intelligence Reporter or UNICOM Intelligence Reporter - Survey Tabulation (version 2.3 and later), and a Quanvert variable has an m;ex= element or an n01;ex= element, the expression is automatically evaluated and displayed on the table.
Create a derived element using relative position to reference elements
When referencing other elements in a derived element, the simplest method is to reference the elements by name, as in the previous example. An alternative method of referencing elements by relative position is also available, using the syntax @ n to reference an element n positions before the derived element. This example uses relative position syntax to create the same table as in the previous example:
age{.., Derived '55 or over' derived('@1 + @2')}
This method can be useful if you want to reuse an expression for elements that are in the same relative position but have different names. However, it is available only for referencing elements that come before the derived element in the table. To reference elements that come after the derived element, you must use the element name.
Create a derived element calculated from other elements using a function
interest{.., Derived 'Highest other than Dinosaurs'
   derived('maxof(Conservation, Fish_and_Reptiles, Fossils,
            Birds, Insects, Whales, Mammals, Minerals, Ecology,
            Botany, Origin_of_species, Human_Biology,
            Evolution, Wildlife_in_danger)')}
This example uses a derived element to compare other elements in the table and display the maximum value, using the MaxOf function.
Here is a table that has this axis on the side:
This graphic is described in the surrounding text.
You can use any expression that is supported by the Data Model, including any of the functions in the Function Library.
See also
Special elements