The following are some formula examples.
|
Purpose: In your sales report, you want JReport to print out which territory the customer belongs to according to the abbreviated state names stored in the State field.
Explanation: In the six else-if statements, JReport will retrieve the value of the State field, and compare it with the values in brackets []. If a value matches the value in brackets, the formula will return the territory name.
|
Purpose: In your sales report, you want JReport to print out the month name of the orders, so that you can compare the orders of each month in a year.
Explanation: Since the database field Order Date is of the TimeStamp data type, the built-in function Month (DateTime) is first used to extract the month portion of Order Date. Then, the else-if statement is used to decide the month according to the return value of the function, and assigns a String value which contains a relative month name to the pre-declared string variable str.
|
Purpose: This formula is used to control the Suppressed property of a certain section such as Page Header, so that the section will be suppressed on the first page of the report.
Explanation: Since it is only required to suppress the section on the first page, if only the Suppressed property of the section is set to true in the Report Inspector, then it will be suppressed on every page. In this formula, a Boolean type variable is first declared. Then, an else-if statement is used to decide whether or not the page is the first page. If the statement is true, true is assigned to "s". If the statement is false, false is assigned false to "s". In this formula, pagenumber is a special field.
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.
pagenumber;
global number pagetotal;
pagetotal=0;
pagetotal=pagetotal+@"YTD Sales";
return pagetotal;
This example will accumulate the total of the successful and failed shipments for each group.
|
if(@Shipped) { iSuccess=iSuccess+1; iFail=iFail; } else { iSuccess=iSuccess; iFail=iFail+1; } |
return "Total successful shipments is "+ iSuccess +" and total failed shipments is "+ iFail;