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.

Finding the Acending of 4 Variables

Featured Replies

Hi, I have an interesting problem that I can solve myself but it seems to be taking too may variables and manipulations that must be easier.

I have 4 global variables within a record, let's call them V1 V2 V3 and V4. Is there any way to sort these variables Lowest to highest? For instance, I have numbers in each variable such as v1=25 v2 = 65, v3=75 and v4=35. Is there a way to sort these variables into positions lowest to highest? Maybe set 4 new Global variables with the sorted value like S1=25 S2=35 S3=65 and S4=75?

I can get the lowest and the highest with the Min and Max functions but I can't seem to figure out the other two middle ones. Any thoughts? Thanks.

What is the purpose of this? Variables are temporary storage holders. I cant see why you would need to do this. Please elaborate.

This seems like fun, I'll have a go.

  s1 set to: Min(v1,v2,v3,v4)

  s4 set to: Max(v1,v2,v3,v4)

Now the harder ones could be done as:

  s2 set to: Case(s1=v1; Min(v2;v3;v4); s1=v2; Min(v1;v3;v4); s1=v3; Min(v1;v2;v4); Min(v1;v2;v3))

  s3 set to: v1+v2+v3+v4 - (s1+s2+s4)

It seems like that s2 could still be made to use less comparisions, via a binary search. But that isn't important if there really will only ever be 4 variables:

  s2 set to: Case(s1=Min(v1;v2); If (s1=v1;Min(v2;v3;v4); Min(v1;v3;v4)); s1=v3; Min(v1;v2;v4); Min(v1;v2;v3))

Edited by Guest
Clarify = verus setting variable.

  • Author

You know, that just might work! I guess you could also set S3 equal to the same as how you did S2 except change Min to Max, but that is not as creative as your way. I like it!... Thanks.

I came to think of what I would do if the number not in any way could be predicted ... recreating somewhat like dynamic value list and ValueListItems( if we just could link on the record ID in a self join. When dealing with variables must it be some way to deal with it in a script regardless of context.

If we define a CF like JMO's:

LeftWords(Case(End + 1 > Start; Start & "¶" & Range(Start + 1; End)); 999999999)




Could it be used in a calc' this way:





Let([

t=Substitute ( input ; "-" ; "¶" );

tt=Substitute ( input ; "-" ; ";" );

ttt=Evaluate("Min(" & tt & ")");

tttt=Evaluate("Max(" & tt & ")")];

LeftWords(Substitute(FilterValues ( Range ( ttt ; tttt ) ; t );"¶";"-");99999999)

)

Other sorting algorithms like Bubble Sort might though be faster - since there always are a price to pay when using Evaluate( speedwise:

http://www.briandunning.com/cf/27

...or the QuickSort:

http://www.briandunning.com/cf/89

--sd

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

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.