Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

A.41 Tutorial A-5 Comparative Income Statement, Part 3

  1. If you preview the report, you should see that the balances for the account class sub-totals are shown as positive for both years. This is looking closer to the original income statement now. We need to make the same changes for the section balances because those amounts are still shown as negative. The difference is that the sections use a running total formula to calculate their balance. We need to modify the running-total calculation so that it will flip the sign for the prior year amounts.
  2. Right-click the Row #1 summary field and select Format Field. This opens the Format Field dialog box.
  3. Click the Common tab and then click on the Formula button next to the Display String option.
  4. Enter the following formula:

//Reverse the sign for prior year balances
numbervar FlipSign := 1;
if Year(GridRowColumnValue("Journal_Entry.Date")) < {?Year To Print} then
FlipSign := -1;
global numbervar RunningTotal;
//Reset the running total balance for the first section in each column
if GridRowColumnValue("@Section ID")=1 then RunningTotal := 0;
RunningTotal := RunningTotal + ToNumber(CurrentFieldValue);
//Display the running total in the current cross-tab cell
ToText(RunningTotal * FlipSign) & " ";

  1. The first part of this formula uses the same logic as the @Amount formula from earlier. It creates a variable called FlipSign and stores a -1 value for the prior year amounts. The remaining portion of the formula is almost identical to the original formula. The difference is that on the last line the RunningTotal variable is multiplied by the FlipSign variable. This negates the balance for the prior year.
  2. Click the Save and Close button and then click the OK button to save your changes and return to the report designer.
  3. If you preview the report, you'll see that the section balances show the correct amounts and they are no longer negative. The two columns that list current and prior years should be identical to the income statement from the previous tutorial.
  4. Even though we turned on the Total column at the beginning of this tutorial, we haven't done anything with it yet and it isn't accurate. It needs to have the sign for its expense accounts flipped and the section sub-totals need to be changed to running totals.

The Total column has separate formatting from the rest of the cross-tab object fields and it needs to have its own formulas built. We are effectively going to copy the formulas from the original income statement and apply them to the fields in the Total column. Since the Total column is not specifically related to a particular year, we don't have to add the additional logic that tests for the prior year and flips the sign.

  1. Right-click on the Row #2 total field (located in the last column) and select Format Field. This opens the Format Editor dialog box.
  2. Click on the Number tab and click the Customize button. This opens the Custom Style dialog box.
  3. Find the option Reverse Sign For Display and click on the Formula button next to it. This opens the Formula Workshop dialog box.
  4. Enter the following formula:

GridRowColumnValue("@Account Class ID") <> 17;

  1. Click the Save and Close button and click the OK button to save your changes and return to the report designer.
  2. If you preview the report, you'll see that the signs for the amounts in the account class total column are correct. Next, we have to modify the section sub-total so that it is a manual running-total formula.
  3. Right-click on the Row #1 total field (located in the last column) and select Format Field. This opens the Format Editor dialog box for the Section ID sub-total field.
  4. Click on the Common tab.
  5. Find the Display String option and click the Formula button beside it. This opens the Formula Workshop dialog box.
  6. Enter the following formula:

global numbervar GrandRunningTotal;
GrandRunningTotal := GrandRunningTotal + ToNumber(CurrentFieldValue);
//Display the running total in the current cross-tab cell
ToText(GrandRunningTotal) & " ";

  1. This formula creates a variable called GrandRunningTotal and for every section it adds the CurrentFieldValue amount to it. It displays the running total balance on the cross-tab using the ToText() function.
  2. Click the Save and Close button. Then click the OK button to save your changes and return to the report designer.
  3. If you preview the report now, you should see that the report is almost finished. All the balances in the Total column correctly subtract the prior year balance from the current year balance and display the result. The signs on all the numbers are correct as well. There are just a few minor formatting issues that need to be fixed before you are finished.
  4. Right-click on the Total column header field and select Edit Text.
  5. Enter the text "Change". This tells the user that the last column represents the difference between the two years and not the total balance.
  6. Click on the Row #1 total field and then click the Bold button. This makes the field bold so that its format matches the other section fields.
  7. Click on the Row #2 total field and then click on the Currency button. This turns off the currency formatting for that field. None of the other fields in the cross-tab are formatted as currency so this one shouldn't either.

Save your report and preview it. It should look similar to Figure A-16.



Figure A-16. Multi-year comparative income statement.