How to get the min & max value of a field?

I want to get the min and max value of a field of a recordset. I know I can set this field as a key, and move to the first and the last record to get the min and max value. But it seems not a efficient method. Any another way?

hi i do it by making the desired field as a flowfield in another table. In fact i have a table that contains all the max or min Vlaues that i require from other table. May be not a great idea but it works fine. WR Hari

Hi, Maybe you should simply use Navision… Value := Record.GETRANGEMIN(Field) Value := Record.GETRANGEMAX(Field) [;)]

hi what if there is no filter on the recordset. The getrangemin and getrangemax function works only when there is a filter set on the recordset…[:D] Hari

Well, put a filter <> ‘’ [:D][:D][:D]

John - did you try that solution yourself? GETRANGEMIN & -MAX does only work if you have from-to-range… ww s - I do not think there is better way around.

Hi WWS, did this answer your question?

quote:


Originally posted by wws
I want to get the min and max value of a field of a recordset. I know I can set this field as a key, and move to the first and the last record to get the min and max value. But it seems not a efficient method. Any another way?


Why is this not an efficient metod? How would i do it: You gona need key anyway. 1. But you can use flowfield in the same table with min/max function. There is limitation, that you this work on the whole table. If you wat record set, then you have to use flowfilter fields. And do not forgnet CALCFIELDS before using min/max flowfield. 2. Or if you hate calcfields and hate to add new fields, than add two function GetMin and GetMax,… Good side is, that it will work only on your curreent recordset GetMax() : Code[10] recLocal.COPY(rec); recLocal.SETCURRENTKEY(Field); recLocal.FIND(’-’); EXIT(recLocal.Field); Regards Bostjanl

quote:


Why is this not an efficient metod? How would i do it: You gona need key anyway. 1. But you can use flowfield in the same table with min/max function. There is limitation, that you this work on the whole table. If you wat record set, then you have to use flowfilter fields. And do not forgnet CALCFIELDS before using min/max flowfield. 2. Or if you hate calcfields and hate to add new fields, than add two function GetMin and GetMax,… Good side is, that it will work only on your curreent recordset GetMax() : Code[10] recLocal.COPY(rec); recLocal.SETCURRENTKEY(Field); recLocal.FIND(’-’); EXIT(recLocal.Field); Regards Bostjanl


Thanks, Bostjanl. Both of the method works well. Considering of system performance, I prefer using the second method, that is, using the key. I think CALCFIELDS function would take much time to calculate. Am I right?

quote:


Originally posted by wws Thanks, Bostjanl. Both of the method works well. Considering of system performance, I prefer using the second method, that is, using the key. I think CALCFIELDS function would take much time to calculate. Am I right?


I have not test both metods side by side, but there is no reason why CALCFIELDS should be slower. In both metods you should use/make key, (CALCFIELDS automaticly selects best key possible. Without good key, CALCFIELDS works VERY SLOWLY)… But with your own function there is more flexibility. Regards Bostjanl