In this tutorial you will redo the previous exercise, but this time you will do the calculations with the Formula step.
writing
. [writing]/20
. You will notice that the sentence is red if it is incomplete or the syntax is incorrect. In that case, the error is shown below the editing area, like in the following example: Number
as the type for the new field, and type writing
in the Replace value column. avg
and click the Formula cell to edit it. average([writing];[reading];[speaking]; [listening])
. Number
.You read the examination.txt
file, and did some calculations using the Formula step to see how the students did.
It may happen that the preview window shows you less decimal positions than expected. This is a preview issue. One of the ways you have to see the numbers with more decimals is to send the numbers to an output file with a proper format and see the numbers in the file.
As you saw, you have quite a lot of functions available for building formulas and expressions. To reference a field you have to use square brackets, like in [writing]
. You may reference only the current fields of the row. You have no way to access previous rows of the grid as you have in the Calculator step and so you needed two Formula steps to replace a single Calculator. But you saved auxiliary fields because the Formula allows you to type complex formulas in a single field without using partial calculations.
When the calculations are not simple, that is, they require resolving a complex formula or involve many operands, then you might prefer the Formula step over the Calculator.
The Formula step uses the library Libformula
. The syntax used in LibFormula
is based on the OpenFormula
standard. For more information on OpenFormula
, you may visit http://wiki.oasis-open.org/office/About_OpenFormula.
Let's play a little with the examination file. Suppose you decide that only those students whose average grade was above 3.9 will pass the examination; the others will not. List the students ordered by average (desc.), last name (asc.), and name (asc.). The output list should have the following fields:
Student code
Name
Last Name
Passed (yes/no)
average grade
Suppose that you want to create a new field as the student_code
plus the name
of the student separated by a space, as for example 867432-94 Linda Rodriguez
. Which of the following are possible solutions for your problem:
a. Use a Calculator, using the calculation a+b+c
, where a
is student_code, b
is a space, and c is the name
field.
b. Use a Formula, using as formula [student_code]+" "+[name]
c. Use a Formula, using as formula [student_code]&" "&[name]
You may choose more than one option.
3.12.136.63