The next step will be to add two formulas to the report.
This report should display a summation for quarter 1 and quarter 2.
1.
Click back to Main Report design view.
2.
Right click on the Formula Fields node and select New…
3.
Enter Quarter1 for the name and click the Use Editor button.
This formula will create a variable to hold the running
total of any sales that occurred in quarter 1. Variables have three options
for scope: Local, Global, or Shared. Local means that the variable is used in
the specific function and its value is lost once the formula exits. Global
means that the variable will retain its value even after the function exits and
can be used in other formulas in the report. Shared means you can use this
variable in other formulas or even sub reports. By default if you omit the
scope of a variable it is Global.
4.
Enter the follow code for the formula text.
Global NumberVar quarter1;
if DatePart('q', {SalesHeader.SalesDate}) = 1 then
quarter1 := quarter1 + ToNumber({SalesHeader.Total})
else
quarter1 := quarter1
This creates a global variable called quarter1. The code
then checks if the date is in Quarter 1. If it is then it is added to the
quarter1 variable.
5.
Click the Save and close button and then add the formula to the Details
section.
6.
Click the Main Report Preview button and you'll see the running total in
the Details section.

7.
Click back to the Main Report design view. Create a second formula
field called Quarter1 and set the formula text to the following.
Local NumberVar quarter2;
if DatePart('q', {SalesHeader.SalesDate}) = 2 then
quarter2 := quarter2 + ToNumber({SalesHeader.Total})
else
quarter2 := quarter2
8.
Save the formula and drag it to the Details section next to the Quarter1
formula and click the preview button.

Notice that the field is not a running total. That is
because the variable was declared as Local rather than Global.
9.
Click back to the design view. Right click on the Quarter2 field in the
Details section and select Edit Formula from the pop-up menu. Remove the word
Local before the variable declaration. By default it will be Global. Click
Save and close and then preview the report again. This time you'll get the
summarized total for Quarter 2.
10. Click
back to the design view. Drag the Quarter1 and Quarter2 fields to the report
footer in their respective columns.
11. Delete
the Quarter1 and Quarter2 field from the details section.
12. Right
click on the Details section and select Suppress (No Drill-Down) from the
pop-up menu.
13. Now
if you preview the report you will only see the totals rather than the running
total.