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

Max Value

Status
Not open for further replies.

CPK6104

IS-IT--Management
Dec 19, 2007
57
US
I think I'm making something harder than it should be... but here goes.

I have the following five fields:
@White
@Red
@Yellow
@Green
@Blue

Each field has a formula and the resulting numeric values will be:
@White 1 if true 0 if false
@Red 2 if true 0 if false
@Yellow 3 if true 0 if false
@Green 4 if true 0 if false
@Blue 5 if true 0 if false

Each row contains each of the 5 fields. Results can vary from record to record... meaning you can get any combo of numbers.
I want to find the maximum value among the 5 fields.

So if for instance the resulting values in a row are 1 0 3 4 0, I want the find the max (4)

Make sense? Thanks for the help.


 
You are making this harder than it needs to be by the use of imaginary field names and made up data. You refer to fields (eg @White), but use the @ symbol in the name which suggests it is a formula.

Pretty sure what you want is straight forward, but it would be easier to provide assistance if you provide:
> real (or at least realistic) table names, data and results sought; and
> details of the code from your formulas.

Pete
 
A formula like this one will return the maximum value

if {@Blue} <> 0 then {@Blue}
else if {@Green} <> 0 then {@Green}
else if {@Yellow}<> 0 then {@Yellow}
else if {@Red}<> 0 then {@Red}
else if {@White}<> 0 then {@White}
else 0


You can avoid creating additional formulas by checking directly the Boolean fields and returning a number related to the order
if {Blue} then 5
else if {Green} then 4
else if {Yellow} then 3
else if {Red} then 2
else if {White} then 1
else 0

Viewer and Scheduler for Crystal reports and SSRS.
 
I see how bad my original explanation was now... sorry about that. Pater, thanks for getting me back on track.

This did it (very simple):
if {@Color Blue}=5 then 5
else if {@Color Green}=4 then 4
else if {@Color Yellow}=3 then 3
else if {@Color Red}=2 then 2
else if {@Color White}=1 then 1
else 0

Sometimes it helps to walk away and look at it the next day. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top