Message Boards Message Boards


Sorting Variables To Find Top 2

Sorting Variables To Find Top 2
5/16/23 3:12 PM
I'm looking for the best way to sort five variables largest to smallest while retaining their identification. 

In my project, I'm accumulating scores in five categories, and need to know what the top two categories are based on the scores. I'm sure I could create a bunch of conditional statements to work it out but I'm thining there's an easier way.

0 (0 Votes)

RE: Sorting Variables To Find Top 2
5/16/23 4:28 PM as a reply to Bryan Lambert.
Hi Bryan,
Great question! Yes, it's possible, and creating a bunch of conditions would be a pain. Here's how you can sort a list of values, and then work backwards using a second list of names to figure out the order.
Sample file:

Since we spoke last, we found out there's already a block that sort of handles this. Check out page 2 of file above. It requires formatting the data in a particular way - a List, and each entry in that List is a Map with two entries - name and count (those names are arbitrary, they could be category and score). With this method the logic is much simpler (one action block to sort), but the overhead of putting it in the right format and extracting the data that you need is higher.

List of Maps video:

Let us know if you have any questions!
0 (0 Votes)