Search code examples
crystal-reports

Referencing the last row's data in Crystal Report


I have a report where the fields come from data pulled from a SQL server. I have a total field that i have added to the report...however i have an interesting conundrum--i was hoping someone had a formula i could use.

Three of my columns do NOT need summation...however my project requirements are telling me instead to just pull the last number from the last row in the report and putting that in the total row. To better clarify:

1999   0.1%   0.2%   0.3%
2001   -2%    0.3%   3.4%

Basically, in the total field, i'd be pulling the values from 2001 since it is the last report row. In my total row, i want to have -2%, 0.3% and 3.4% showing (since those are the last row's values). SO basically, i just want to pull the last report row's data (NOT total it).

Anybody have a formula i can use for this?


Solution

  • Well, I have two formulas you can use... I think the only way to do this is with a variable to capture the final value in the details section, and then display it in the group footer. So, in details, create formula field like this:

    shared CurrencyVar lastValue;
    if (OnLastRecord) then
      lastValue := {my_table.field_name}
    

    Add this to your details section and suppress it (so it doesn't display). Then add another formula like this:

    shared CurrencyVar lastValue;
    lastValue;
    

    Add this to your group section where the total would normally go.

    You will need another set for formulas for each field you need to handle this way. Note that you could handle all the fields in the first formula if you use basic syntax (so you can have multiple statements under the 'if').