It is possible to perform calculations while constructing a query.You can add a new field to the query that calculates, for instance, a20% markup on products or a 30% increase in outstanding accountpayments. As long as you have existing fields within the table on whichto base the calculation, it’s extremely easy. To construct such a query,follow these steps:
- Open the ElkAdmin.accdb database. Locate the
OutstandingAccounts query and double-clickto open it in Datasheet View. Take afew seconds to look at the data provided in the query.
- View the query in DesignView.
- Add a new field called CHARGES tothe query grid to the right of the
OUTSTANDING field. The field must calculatea 20% increase in the outstanding amount, as illustrated in thefollowing screenshot:
- There are two methods to enter the calculation into the field,as follows:
- The first method is to create a new field in thecolumn alongside OUTSTANDING. You mustinsert a colon after the new name—for example,
CHARGES. When using fields incalculations, you need to surround the field name with squarebrackets—for example, [OUTSTANDING]. To work out 20% of theoutstanding amount, you would type *.2. Therefore, thecalculation would be as follows: CHARGES:[OUTSTANDING]*.2.
- The second method would be to use the
Builder button located on the Query Setup group to help formulate thecalculation. Click on the Builderbutton to launch Expression Builder,as illustrated in the following screenshot:
The dialog box contains
Alternatively, type the expression yourself into the build areaprovided at the top of the dialog box. Remember to place a colon aftertyping the field name to separate the name from thecalculation.
- Click the OK icon once theexpression is complete.
- The expression appears on the query grid as a new column.
- To view the complete expression or make any changes, press theShift key on the keyboard. While this key is depressed, alsopress the F2 function key. A zoom window will open, showing theexpression with enough room for editing.
- Click on the OK icon to return tothe query design.
- Press the Run icon located on theResults group to see the result of thequery.
- Change the view back to DesignView to edit the query, if necessary.