Forum Discussion

DanielGiles's avatar
DanielGiles
Copper Contributor
Oct 19, 2023
Solved

Using dropdown list to sort table

Hello,

 

I am trying to set up a table which can be dynamically sorted based on a drop-down list. This table will effectively just be a ranking table, which has the rank (1-99) in Column A, and the name in Column B. Depending on the value selected from the drop down list I want the names to be sorted based on a column in another table (e.g. salary, years of experience).

 

At the moment I am trying to do this using the SORTBY function. SORTBY(array, by_array1). Where 'array' is the list of names in the more detailed table, and 'by_array1' will be linked to the drop-down list value selected. My approach has been to set up an IF statement which returns the desired array based on the value in the drop-down list. So if you have selected salary in the drop-down list, then the adjacent cell will return the reference of the array (e.g. $F$1:$F$99). I have then set up the 'by_array1' element of the formula to read the value in this adjacent cell to try and force the SORTBY formula to look at the relevant column.

 

This does appear to work, but only once. If I try and change the drop down value to, for example, years of experience then this changes the adjacent cell to $G$1:$G$99, but the table does not re-sort based on the values in $G$1:$G$99.

 

There may be an alternative way to do this, so any guidance would be appreciated. In reality there are a lot of different values in the drop-down list so I would like a dynamic solution, rather than using the built-in sort & filter tools.

Thanks!

 

 

Resources