Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

2ndMax Custom Function

Featured Replies

I'm looking for a simple solution (who isn't?)...

I want to create a 2ndMax function similar to the built-in Max(field1,field2,field3,...) function, but it would return the 2nd highest value. For example, 2ndMax(height,width,depth) would return 12 if height=20, width=12 and depth=8.

Any suggestions?

I have posted a formula, edited it, and now I am removing it altogether.

You need to specify what should happen when the values are:

a) 20 ; 12 ; 12

: 20 ; 20 ; 12

c) 20 ; 20 ; 20

If it's really only 3 values, and you always want the second one in their ordered position, you could use:

h + w + d - Max ( h ; w ; d ) - Min ( h ; w ; d )

  • Author

Thanks for the response. The number of values is not always 3 (unfortunately, because I like the cleverness of your solution). There will be anywhere from 3 to 17 values, and it doesn't matter if there are duplicate values. I have a solution that involves the use of a separate table where each field gets put into its own record, the table gets sorted and then I pull out the 2nd value. I was looking for a different way. It's not that important (since I do have the alternative), so please do not go out of your way to figure this out.

Use valuelistitems function. See attachment.Or i dont understand your wish?

aaa.zip

it doesn't matter if there are duplicate values

But it does matter, because one needs to know how to handle such situation. For example, consider a contest where there is a tie between 2 winners. The results table will look like this:

PLACE....SCORE

1........20

1........20

3........17

So here you have 3 possible answers to 'what is the second best score': it could be 20, it could be 17, and it could be "there's no one in the second place". The basic approach is entirely different in each case.

  • Author

Here are the outcomes I'd like:

2ndMax(20,20,17,10,5) = 20

2ndMax(5,5,5) = 5

2ndMax(1,2,3,4,5) = 4

2ndMax(5) =

The problem with valuelists is (I believe) it doesn't account for duplicates as it would produce the outcome of 17 in the 1st example above instead of 20 which is the desired outcome.

You can overcome the problem with duplicates in a value list using a calculated field = value & " " & Serial number. This will make them unique. It does require a little extra work.

Ralph points in the right direction, IMHO, but it requires more than a little extra work. The concatenation

value & " " & Serial number

is text, and will be sorted by text rules (1, 11, 2 ,21, etc.). Numbers must be processed into text strings in order to be sorted in the desired order. This can get quite complex, even slow, if one needs to anticipate the full range of numeric input.

The attached demo uses a "light" version of pre-processing, dealing with zeros and positive numbers in the range of 10^-9 to 10^9, exclusive.

2ndMax.fp7.zip

  • Author

On second thought, I don't think I can use value lists since I'm looking for the 2nd Max among several fields within a single record, rather than across records (like the Max(field1,field2,field3...) function).

If the number of items is variable, and can go up to 17, and the items need to be compared - they really should go into a separate table with a record per item.

  • Author

OK, Thanks all.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.