cancel
Showing results for 
Search instead for 
Did you mean: 

Max Value

ZahibSidiq
Level 4
hello, 

The fastest way to find the highest number or max value, lets say between three number. Any help is appreciated.  
BR

Zahib
10 REPLIES 10

david.l.morris
Level 15
Could you explain the use case? There are several ways to get the max value in a list of values, but do you also need its associated data? Are these values already in a table or collection? Is it just a list of numbers that are not associated with anything else?

Also, are you looking for the most efficient way to do this or just a way that works?

I'll give two quick options for now.

Option #1: Assuming that you do not care whether that highest number or max value is in the list more than once... Bring the numbers into a collection, where each number is on its own line. Then use the action 'Sort​ Collection' in the VBO 'Utility - Collection Manipulation'. Put the field name into the 'Sort Field' input. And put 'False' in the input 'Ascending Order' so that the highest number will be in the first row. The first row should be selected in the output collection. So, you should be able to use a calculation stage to get the value from the first row like '[Sorted Collection.FieldName]' to get the value. This of course ignores whether row 2, etc. also have the same value. But this is assuming you just want to know that value.

Option #2: The other way to do it that may or may not be more efficient is to (again put the numbers into rows of a collection first) loop through the collection and store the value into a data item each time you find that it is higher. You'd have a decision stage that compares the current number to the last highest number. If it is higher, then you replace the last highest number with the current number and then loop again.

------------------------------
Dave Morris
3Ci @ Southern Company
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

I had three dates which i wanted to find the latest one. What I did was, formated the date to "yyyyMMdd" and then used what you described in option #1 to find the biggest "number" and converted back the number to the original date format. Thanks for your help 🙂 

Mvh

Zahib ​

------------------------------
Zahib Sidiq
Associate
KPMG
Europe/Oslo
------------------------------

That makes sense. You should also be able to sort on a date without changing the format of it assuming it's in a Date data item. But what you did should work solidly too.

------------------------------
Dave Morris
3Ci @ Southern Company
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

Thank you for the tips once again:)

------------------------------
Zahib Sidiq
Associate
KPMG
Europe/Oslo
------------------------------

Hello @Morris_Dave 
I have a similar question, but in this case, I'd like to get the corresponding value under Name in the row with the largest value under Age. I also want to get the Name and lowest value (a number) under Age. I used the sort utility already, so the collection is in size order. I just need to find a way to isolate the top row and the bottom row. 

Hope you can help.
Thanks​

------------------------------
Bernadette Stroeder
------------------------------

Unfortunately, BP does not allow you direct access the first or last row. So, in order to get the highest and lowest value, you'd sort it twice on Age, first descending and then ascending, and after each sort you only read the first row to get the value and the name that comes with it.

Good luck!

------------------------------
Happy coding!
Paul
Sweden
------------------------------
Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)

This is true for anything out of the box. In the backend, a collection is still a .Net DataTable. A code stage can be written to reference a cell/row directly by integer index.

------------------------------
Ami Barrett
Sr Product Consultant
Blue Prism
Plano, TX
------------------------------

Thanks Paul, 

I'll try that! And thanks Ami, always good to get the background on limitations.

Regards
Bernadette

------------------------------
Bernadette Stroeder
------------------------------

Hi Zahib,

I have similar use case to find the max date from collection of dates after sorting. Could you explain how you did the coding.

Thanks in Advance
Marina

------------------------------
Marina Dutta
------------------------------