Print Page | Close Window

Set value if any records match

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22268
Printed Date: 06 May 2024 at 9:09am


Topic: Set value if any records match
Posted By: idavis
Subject: Set value if any records match
Date Posted: 16 Mar 2017 at 8:45pm
I am really struggling with one element within a report.

I have a series of records and what I am trying to do is set a variable if ANY of the records meet a condition. This issue I have is it works if the most recent record meets the condition but the variable (I guess the clue is in the name) changes if the next record does not meet the condition.

For example

Record 1 No - Date 01/01/17
Record 2 No - Date 04/03/17
Record 3 No - Date 11/02/17
Record 4 Yes - Date 01/03/17
Record 5 No - Date 12/03/17
Record 6 No - Date 09/01/17

The report is grouped so the records above are in a sub group of a supplier.

In this example the report returns the date 09/01/17 and I am trying to get it to return Record 4 Yes - Date 01/03/17.

I use the If record = "No" but this only works if "No" is TRUE for the last record in the cycle. It cycles on to the last record so the final return changes as the condition is no longer met.

Any ideas or advice would be very much appreciated.

Kind regards,

Iain.



Replies:
Posted By: DBlank
Date Posted: 17 Mar 2017 at 4:41am
Can you explain more what the purpose is for this, if you are doing more calculations from the 'result' and exactly what and where you need to display the content?


Posted By: idavis
Date Posted: 20 Mar 2017 at 4:20am
I am trying to use 01/03/17 as the date something starts in a time calculation.

Record 4 Yes - Date 01/03/17

The issue I have is the variable pages through and changed to Record 6 No - Date 09/01/17.

Kind regards,

Iain.


Posted By: lockwelle
Date Posted: 24 Mar 2017 at 6:49am
set a formula is my answer...a one time flag, so to speak...this may or may not be what you mean.

shared booleanvar isFound;
shared stringvar dateWant;

if {table.column} = someCriteria then (
isFound := true;
dateWant := {table.column2};
);

""

you would need to reset the variables at the correct group level and report on them at the correct group footer.

Hope this gives a road map



Print Page | Close Window