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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formulas by Group

Status
Not open for further replies.

Bontebok

Programmer
Nov 18, 2002
63
US
Greetings,

As I understand, the Maximum function can be used to return the maximum value in a set. This allows you to determine the Maximum value in a group. This is not working for me because the type of the value changes from a number to a text in some cases.

Is there a similar function that will determine the result of a formula in a group?

For instance:

GroupValue({@BooleanFormula}, {Value}, {Group})

And how this would work would be the BooleanFormula would be ran for each set in the Group, and the Value would be returned if the result of the formula was true.

Does anyone know another way to achieve something similar to this?

Thanks,

Jeremy Bair
 
You can only take the maximum of one column, and that column cant change data type in the middle of the column. Is either numeric or text. Can you give an example of the values in the column and how you want them to appear on the report? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken,

Certainly.

The values in the column are a result of the following formula called "Value":

select {PatientResultsSP;1.test}
case 32:
{PatientResultsSP;1.textresultstr}
...
default:
if IsNull({PatientResultsSP;1.decimal}) then
ToText({PatientResultsSP;1.numresult},0)
else
ToText({PatientResultsSP;1.numresult},{PatientResultsSP;1.decimal})


If the value of the test column is 32, then the result of this field should be the textresult. Else, format the number according to the rules in the database for the number of decimal places and return.

The return type of this formula should always be a text field. I assume passing Maximum a text value with something that can be evaluated with IsNumeric() causes a conversion from text to number.

The grouping is done on the test number above.

I would do this inside of the Details area myself, but I haven't figured out how to create a global variable. I seem to only be able to create local variables.

Thanks,

Jeremy Bair
 
>>I assume passing Maximum a text value
>>with something that can be evaluated with IsNumeric()
>>causes a conversion from text to number.

This is not true. Taking the maximum of a text value will find the value that would sort last Alphabetically. The max of 9, 50, 200 is 9 if they are strings. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken, I don't understand why I am not getting any values from the Maximum() function against my set.

Since a formula doesn't have a specified return type, I assume it's return type is equal to the output type of your formula. Is this true? Is there a way I can evaluate this? Like typeof() in javascript?

So this formula:
numberVar x:= 1;
x

Would return a type of numeric, but this formula:
stringVar x:= "1";
x

Would return a type of text/string?


Maximum must make a distinction from values of different types, as you said, the maximum of "9", "50", "200" is not the same as the maximum of 9, 50, 200.

When does this occur? The in the first evaluation of the formula? Does this ever reset on change of group (if you are returning the maximum of a group).

Thanks,

Jeremy Bair
 
A formula can't change data type during the report. The data type is determined when you save the formula.

That being said, it is not clear what you are trying to do with your formula. I have no idea what a 'set' is. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken,

After some testing, I found what you stated above, that the data type is determined when you save the formula. Unfortunately, the method I was trying to use would require Crystal to be able to alter the data type of a formula during print time.

I moved the two different data types into two separate formulas, and used a main formula to determine which data should be displayed. And in that formula, I did the appropriate ToText conversion of the numeric data type.

This appears to be working great. Oh, a "set" is mentioned in the Maximum() manual page. "Enables you to find the maximum value that appears in a set of values.", I was using that term to describe the values inside a group.

Thank you for your help,

Jeremy Bair
 
That is a generic term probably since Max can go down (a group of details) or across (a specified list of fields). Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Hello,

If you want to get the first or last record in a group no matter if it has numbers or alpha you can do this in the Details format section.
Example:
File Number for one file that has many records.
Choose Suppress, no-drill down, x+2
Type:
not onfirstrecord and
{tblFCMain.sFCFileNumber} =previous({tblFCMain.sFCFileNumber})

what this does is choose the most recent action on this file.

Let me know if this is what you are looking for.
Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top