Working with expressions
Use an expression to create a calculated field from one, or multiple fields in a database. You can create an expression that concatenates strings by joining several fields or a complex expression that uses mathematical operations, such as logarithms. For expressions generating a decimal field, you can specify precision up to six decimal places. For example, a typical calculated field can display customer orders based on the year in which each order was placed.
To further demonstrate, you can use the following equations to accomplish the listed tasks:
*Concatenate Text (+): join two text fields.
[Demo].[Customer].[Title]+[Demo].[Customer].[Surname]
*Concatenate (+): join two numeric fields or strings.
STRING([CustomerID])+5+[DaysSinceLastOrder]-1
*Mathematical functions (+, -, *, /): numeric fields can be added, subtracted, multiplied, or divided.
STRING([Demo].[Customer].[Cust_ID]+[DEMO].[Customer].[Household_ID])
*Boolean values: (logic 1, logic 0) assignment of Boolean values to fields, based on the conditions that are established.
[Demo].[Customer].[Edats]EQ"Adults">0 or [Demo].[Customer].[Edats]EQ"Joves">0
*Constants: a constant is a fixed value; in this case a constant function is one that gives a single value for a set of variables.
[Demo].[Customer].[Household_ID]=1
This expression returns the value to position 1 in the Household_id field.
*Conditional Boolean value (Boolean if statements): complex conditions can be tested, such as whether the customer’s age has a specific characteristic. Returns either true or false. Instead of returning true or false, the expression can return other values, such as yes or no.
If([DEMO].[Order].[OrderDate]>[Demo].[Customer].[DOB],1,0)
To display help for a function, double-click the function. Figure 3‑17 shows the help for the AGE function.
Figure 3‑17 Help for AGE function