BackPrevious Page Next PageNext

Creating a Formula

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

  1. Open the requied catalog.
  2. In the Catalog Manager, expand the data source in which to create the formula, then:
  3. In the Enter Formula Name dialog, provide a name for the formula and click OK. The Formula Editor appears.

    Formula Editor

  4. Compose the formula by selecting the required fields, including DBFields, other formulas, summaries and parameters in the current catalog data source and some special fields from the Fields panel, and functions and operators from the Functions and Operators panels. When the predefined formulas, summaries and parameters cannot meet you requirement, you can create new formula, summary and parameter to be referenced by the formula using the New XXX option on the toolbar. The newly created objects are saved into the same catalog data source as the formula. You can also write the formula by yourself in the editing panel. You should have some knowledge of the formula syntax before you can successfully compose a formula with no errors.

    Make use of the buttons on the toolbar above the editing panel to edit the formula. To comment a line, click the Comment/Uncomment button Comment/Uncomment button on the toolbar. If you want to bookmark a line so that it can be searched easily later, click the Add Bookmark button Add Bookmark button. To check whether or not the syntax of your formula is correct, click the Check button Check button.

  5. When done, click the OK button to add the formula.

Notes:

Below are some formula examples:

Example 1: TerritoryUSA

if (@State in ["CT", "ME", "MA", "NH", "NY", "RI", "VT"]) {
  "NorthEast, USA";}
else if ( @State in ["DC", "DE", "MD", "NJ", "PA", "VA"]) {
  "MidAtlantic, USA";}
else if ( @State in ["CO", "ID", "KS", "MT", "NE", "NV", "NM", "ND", "SD", "UT"]) {
  "Rockies, USA";}
else if ( @State in ["AZ", "AR", "LA", "MO", "OK", "TX"]) {
  "South, USA";}
else if ( @State in ["AL", "FL", "GA", "MS", "NC", "SC"]) {
  "SouthEast, USA";}
else if ( @State in ["AK", "CA", "HI", "OR", "WA"]) {
  "West, USA";}
else if ( @State in ["IL", "IN", "LA", "KY", "MI", "MN", "OH", "TN", "WI", "WV", "WY"]) {
  "MidWest, USA";}

Example 2: DateToMonth

Number m = Month ( @"Order Date" ) ;
String str = "";
if ( m == 1 ) {
  str = " January Sales";}
else if ( m == 2 ) {
  str = " February Sales";}
else if ( m == 3 ) {
  str = " March Sales";}
else if( m == 4 ) {
  str = " April Sales";}
else if( m == 5 ) {
  str = " May Sales";}
else if ( m == 6 ) {
  str = " June Sales";}
else if ( m == 7 ) {
  str = " July Sales";}
else if( m == 8 ) {
  str = " August Sales";}
else if ( m == 9 ) {
  str = " September Sales";}
else if( m == 10 ) {
  str = " October Sales";}
else if ( m == 11 ) {
  str = " November Sales";}
else if ( m == 12 ) {
  str = " December Sales";}

Example 3: SectionInvisible

boolean s;
if (pagenumber==1){
  s=true;}
else {
  s=false;}

Example 4: Running total of page

You can use the running total function to calculate the sum of one page. And to use the running total function, you have to create a set of formulas.

  1. Create a formula named Formula1 as follows to initialize a global variable as the sum variable. And insert it into the BandedPageHeader panel. The reference to PageNumber forces the calculation to run after the page break. For more information, see Formula Levels.
    pagenumber;
    global number pagetotal;
    pagetotal=0;
  2. Create a formula named Formula2 as follows to accumulate the value. And insert it into the Detail panel.
    pagetotal=pagetotal+@"YTD Sales";
  3. Create a formula named Formula3 as follows to display the sum of one page. And insert it into the BandedPageFooter panel.
    return pagetotal;

Example 5: Running total of group

This example will accumulate the total of the successful and failed shipments for each group.

  1. Create a formula named Formula1 as follows to initialize the value. And insert it into the group header.
    global integer iFail;
    global integer iSuccess;
    iFail=0;
    iSuccess=0;
  2. Create a formula named Formula2 as follows to accumulate the value of the successful and failed shipments, and insert it into the Detail panel.
    if(@Shipped) {
      iSuccess=iSuccess+1; 
      iFail=iFail; 
    }
    else {
      iSuccess=iSuccess; 
      iFail=iFail+1;
    }
  3. Create a formula named Formula3 as follows to return the successful shipments and the failed shipments, and insert it into the group footer.
    return "Total successful shipments is "+ iSuccess +" and total failed shipments is "+ iFail; 

Note: Global variables are not supported in dynamic formulas so an alternate way to do this is using two formulas (fShipped and fNotShipped) to return either 1 or 0 based on @Shipped:

if(@Shipped) return 1 else return 0;
if(@Shipped) return 0 else return 1;

Then add dynamic aggregations to sum on fShipped and fNotShipped. The result will be the same as using the global variables.

BackPrevious Page Next PageNext