Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get a Minimum Result from a Formula? 1

Status
Not open for further replies.

omcompany

Programmer
Aug 30, 2011
29
US
I am creating a report where I have to get the difference between two numbers (Number - Next(Number)) and then show the minimum result.

I am using Crystal 11 connecting to sql database.

I get all the records from a single Database Field called (as an example) Hole.Time. The field is sorted by Descending values. The values are whole numbers. An example of what I would be pulling in is (30,25,20,19,15,15,10,10,5,0) No grouping necessary that I can tell.

Here is what I have so far with the research I have done.

//{@MinResult} Placed in the Report Header a (RH-a)
WhilePrintingRecords;

NumberVar Min :=0;


//{@MinDelayTime} Placed in the Details section
WhilePrintingRecords;

NumberVar Min:={ShotTimingDetail.DeckFiringTime}-(NEXT({ShotTimingDetail.DeckFiringTime}));

//{@MinDelayTimeResult} Placed in the Report Footer a
WhilePrintingRecords;

NumberVar Min;
Min;



The report shows the difference between the two records correctly in the details section. What I need is to show the minimum value from that list of differences.

If I try to use Minimum({@MinDelayTImeResult}) or anything like it I get the "cannot summarize field" error.

I have seen many posts on how to get the Sum of formulas but none for getting the Minimum result.


Any help is greatly appreciated.




 
First remove the formula from the report header, as it is unnecessary. Then change the detail formula to:

//{@MinDelayTime} Placed in the Details section
WhilePrintingRecords;
numbervar diff;
NumberVar Min;
if not onlastrecord then
diff := {ShotTimingDetail.DeckFiringTime}-NEXT({ShotTimingDetail.DeckFiringTime}) else
diff := diff;
if onfirstrecord then
min := diff else
if diff < min then
min := diff else
min := min;

Use your original report footer display formula.

-LB
 
Thank you very much for your help. This is working just as I expect it to. I will learn from your solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top