Message Boards Message Boards

Back

Sorting Variables To Find Top 2

Toggle
Sorting Variables To Find Top 2
Answer
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.

Thanks!
0 (0 Votes)

RE: Sorting Variables To Find Top 2
Answer
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.
Video: https://share.smartbuilder.com/public/support/sorting-values.mp4
Sample file: https://share.smartbuilder.com/public/support/sorting-values2.sb4

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: https://share.smartbuilder.com/public/support/sorting-values-part2.mp4

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