## Creating a formula

To create a formula in catalog, follow the steps below:

1. In JReport Designer, open the catalog to which you want to add the formula.
2. In the Data tab of the Catalog Browser, expand the data source in which to create the formula, then right-click the Formulas node, and then select Add Formula from the shortcut menu.
3. Enter a name for the formula in the Input Formula Name dialog and click OK. The Formula Editor window appears. See the window.

4. Compose the formula by selecting the required fields, functions and operators from the Fields, Functions and Operators panels. You can also write the formula by yourself in the editing panel.
5. To comment a line, click the Comment/Uncomment button on the toolbar.
6. If you want to bookmark a line so that it can be searched easily later, click the Bookmark button .
7. Click the Check button to check whether or not the syntax of your formula is correct.
8. When done, click the OK button to add the formula.

Notes:

- You should have some knowledge of the formula syntax before you can successfully compose a formula with no errors. To learn the formula syntax, refer to topics in Formula syntax.
- If you refer to any field in the formula, the reference name for that field will be prefixed with an @ sign. If the field name contains spaces, the reference name in formula will be quoted with double-quotation marks (""). For example, if the field name is Customer Name, then the reference name will be @"Customer Name".
- When formulas refer display names or mapping names, the names should not contain any of below characters if the names are not quoted by double-quotation marks "":

  "~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "+", "=", "{", "}", "[", "]", "|", "\\", ":", ";", "\", " ' ", "<", ",", ">", ".", "?", "/"

  Examples:

  - Expression @Customer#; will cause a syntax error. But @"Customer#" is ok.
  - If a field has the display name Category.Measure, when adding it to a formula, quote it as "Category.Measure" or "Category"."Measure".
- The number of the "if-else" statements in a formula is limited to 190. When this number is reached, you should use the "select-case" statement instead.
- In the Fields panel, if the summaries or parameters you want to use have not been predefined in the catalog, you can create them by your own by clicking the New Summary button or the New Parameter button on the toolbar (for details, see Creating a summary and Creating a parameter).