Max value

Hi Guys.
I have about 6 or so dynamic properties(type float) which are linked to other properties on the window. How do I find the max value among the 6 and then subtract the rest from it. I know expression has a max function but it needs a dataset to be fed, so If I have to use that then how do I put these 6 or so properties into a dataset? I also know that python has a max function, but than how do I use it here even if I create a 7th dynamic property lets say max to store the maximum value?

Thanks
Qurban

Ok, Q - I’m not not going to win any prizes for elegant code, but this solution will work well and is conceptually simple.

Suppose we’re dealing with your floats, A, B, C, D, E, and F. We’re going to divide and conquer with many dynamic properties.

The first, Total = A+B+C+D+E+F.

Then define as follows: MaxAB = if(A>B,A,B)

Also create: MaxCD and MAXEF.

MaxABCD = if(MaxAB>MaxCD, MaxAB, MaxCD)

and Max is the same thing with MaxABCD and MaxEF.

I assume you meant subtract Max from the Total, which would be Total - Max.

I’ll put in a feature request for the aggregate functions (max, min, avg, etc) to support comma separated lists of numbers in addition to dataSets.

edit - I’m such a hippocrate. Earlier, I told you the term code refers to Jython Scripting, then I knowingly used it to refer to expressions. Humm…

Oh man, there’s an easier way that I just thought of…

Separately Qurban had asked me if there was a way to run jython in an expression, and I said no… but I lied. There’s actually a fairly new function called runScript that will do it. And conveniently, python has a max function.

So, you could so something like the following in an expression:

runScript(concat("max(",{Root Container.Text Field.a},",",{Root Container.Text Field.b},")"))

This just has 2 properties on a text box. So the trick is runScript just takes a string, in this case “max(a,b,c)”. You can’t refer to a dynamic property in a string, so you have to concat them together (could use “+”, but I thought “concat” was cleaner in this case).

I agree that the built in functions should handle this case, but at least this is easier than Nathan’s solution! :stuck_out_tongue:

Regards,

It may be easier (to implement), but it's certainly not simpler.

...and mine works in pre-SQLTags versions
...and I put in a feature request in for the appropriate functions

:stuck_out_tongue:

PS - my method sucks. Go with Colby's.

Yeah, I'm on board with that. It'll be in the 3.1 release.