Custom Function to get max of numbers represented as text

Suppose we are given a field called “Level” having data as 1,2,3,5 … etc as separate records or data separated by carriage return, but as text field.
Then, ExecuteSQL() or Max() function shall not work as the field entries are described as TEXT.

Below is a custom function which resolves the issue.

maxNumFromList(listt;counter1 ;maxx)

listt = the list of numbers
counter1= always 1
maxx = “”

Example:-
————-
maxNumFromList ( “11” & “¶” & “2” & “¶” & “11” & “¶” & “111” & “¶” & “22” & “¶” & “2”; 1 ; “” ) = 111

Let (
[ value1 = GetAsNumber ( GetValue ( listt;counter1 ) );
max =If ( maxx > value1 ;maxx ; value1 );
count1 = ValueCount ( listt );
counter1 = counter1+1

];
If ( counter1 >count1 ; max ; maxNumFromList(listt;counter1 ;max))

)

 

Leave a Reply