views:

219

answers:

2

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?

+1  A: 

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').

Ray
i tried adding the formula for my field in the details section...however 2 questions.1.) it keeps asking me to declare a var type...at which point i tried numberVar. this then prompted Crystal to tell me that it didn't think the rest of the text past my variable declaration was part of the formula2.) user_credit_report_view.amount <-- i'm assuming this is the field name?
1 - try setting your formula editor to Crystal syntax and see if it helps. 2 - yes, I used an existing report of mine to check my syntax, and that is my field name - I am going to edit my answer to make that clear. Also, I used CurrencyVar - you can use NumberVar if that works better for you.
Ray
my formula editor is in Crystal Syntax...however i keep getting errors when i try to put in a variable type. i tried StringVar, NumberVar...still the editor expect something at the end of the statement.
strange - what version of Crystal are you using? can you post your exact formula that is causing the error? You might try building the formula with the tools in the editor (functions and operators windows) rather than typing it in to see if there is some difference.
Ray
i'm using Crystal Reports in Visual Studio--dont' know if this makes a difference or not. but at any rate, i tried declaring: shared StringVar lastValue;if (OnLastRecord) then lastValue := {my_table.field_name}it kept saying that i could not put in "shared" in front of the var -- the message: a 'shared' variable can only be used while printing records.then i went on to put in the rest of the formula. i got this: "a number, currency amount, boolean, time, date-time or string is expected here".
I am also using the VS version. Where are you typing this stuff? I did it in a new formula (right-click on 'formula fields' and select 'new'). Then I dragged the formulas on to the report, the first in the details section and the second in the group. Is this what you are doing?
Ray
ok--clearly i had a moment of stupidity. i was trying to edit this formula WITHIN the field itself. this ended up working VERY well :) thanks for your patience and help! it's so much appreciated!
everyone is entitled to a moment now and then - I used up my annual allotment by February 13th, so I have to be extra careful now :)
Ray
A: 

If I read this correctly, I typically would just put the fields themselves in the footer, without any formulas. The report should display the values from the last record in the group.

GWest