Sorting by a column in your table using a parameter and control

I have a table with a few columns, column A, B, C. I want the sorting of those columns to be controled by a parameter. so Ideally, I will have a paramter named sort by with values A, B, C. and another parameter named sort direction with values ASC and DESC. I want my users to have the ability to sort Column A ASC or DESC, and the same for other columns i my table. How can I achieve this with a calculated field. Can someone please provide a step-by-step process?"

Thank you in advance! :slight_smile:

Hi @huda.h.yazgi,
There are a couple ways you could try and set this up;

The first would be creating a ranking calc. field (x3) that defines the order for each of your desired column fields.
You can save a step by building directly into an ifelse statement but essentially it’ll end up being something along the lines of:
ifelse(
${SortingParameter} = ‘Column A’, {rank of column A},
${SortingParameter} = ‘Column B’, {rank of column B},
${SortingParameter} = ‘Column C’, {rank of column C},
NULL)
Then you can either add that field to your table and then hide it, so that you can set up the sorting to be based on that field. Or you can sort by an off-visual field.

If that does not work as smoothly as preferred, you can also set up to be much simpler. In free-form layout, duplicate your table and set each of them to be ranked by a different field. Then you can setup a rule on each that hides/shows the correct table based on your parameter selection.
If your sheet doesn’t have too many visuals already on it, this may be a much quicker and simpler route to take so that you can edit each ‘view’ individually in case you want to mix up column order as well.

Thank you so much! I used a combination of parameters and rules. I was able to create an ifelse statement with dense rank for the numeric and string fields. But it did work for the date fields so I just duplicated the table and set rules. When using a parameter and calculated field, you have to use it to sort the visual as well. It was strange why the date did not rank properly though