Accessing Data : Adding a computed field to a data set
 
Adding a computed field to a data set
A data set can contain computed data as well as data that is returned from a data source. Computed data displays the result of an expression, typically involving one or more columns from a data source. For example, if each row that is returned from the data source contains a price and a quantity, you can create a computed field that calculates the total amount paid, using the following expression:
row["pricequote"] * row["quantity"]
You can also concatenate values from multiple fields, using the + operator, or calculate values using JavaScript functions. The expression builder provides a list of operators and functions that you can use to build expressions.
You can also define a computed field in the report layout. Defining computed fields in the data set is, however, the preferred approach. Defining the computed field in the data set separates business logic from the presentation of the data. Defining the computed field in the data set also enables you to verify the results of the calculation in the Preview Results page of Edit Data Set. You can determine whether the expression for the computed field is correct before using the field in the report design. Figure 4‑82 shows the Preview Results page including the results of a computed field, Total_cost.
Figure 4‑82 Preview Results including the results of a computed field, Total_cost