How to Click & Sort with a Set Action | Tableau

by Marcelo Ramos

With a set action, you can easily click on a mark on your worksheet and it be sorted for you on Tableau like so:

To do this, you will firstly want to create some kind of chart split up by a dimension. In my case I have a stacked area chart showing categories as a percentage of monthly total sales. I have put 'Categories' on colour to split up the view and this is what we will be changing the sort order of with the set action.

Secondly, you want to create a set of the dimension you are sorting. In my example, I will right click the 'Category' dimension in the data pane and click 'Create...' and then 'Set'.

Name it something memorable and useful, and tick one of the values in the box. Now click OK.

As the Set is currently configured, my 'Furniture' value is IN whilst the other two are 'OUT'. You can think of this like a boolean field where 'Furniture' is TRUE (1) and the others are FALSE (0).

Now you want to create an order you can change for the dimension, that is changed by what is IN the set. Do this by creating a Calculated Field and writing:

What this formula says is: if the category is IN the set then show its sales, whereas for every other category which is OUT of the set, show zero. What we will do now is sort the dimension we want based on this calculation.

Right click your dimension on colour on the marks card and click 'Sort...'.

A window should pop up that has two sections. Under the first, 'Sort By', you want to click the dropdown and change it to 'Field' and choose the calculated field you created for the set action.

Area charts sorts the highest values from the bottom

Now, 'Furniture' is IN the set and has the highest number (the total of sales of that Category), whilst the other categories show a number of zero (which we specified in the calc). Therefore, Category is sorted based on these values and shows 'Furniture' first and the others after until what is IN or OUT of the set is changed.

The sorting section is done, all we need now is the click action which can be easily done by:

  • Clicking 'Worksheet' on the top of the workbook
  • Clicking 'Actions...'
  • Click 'Add Action...'
  • Click 'Change Set Values...'

This all brings up your Set Action configuration for your new set.

You want to have your settings for your Set Action configured like this, where the source sheet is from that specific worksheet and it is targeting the set you created.

Ensure that 'Clearing the selection will' is set to 'Keep set values' otherwise when you click off the clicked section it will reset the sort order.

You will find that there is a really annoying thing that happens once you click a mark on your view. That specific mark will be highlighted and the others will become greyed out. To solve this you need to change the highlighting in the sheet. Check out Maha's blog on it to learn how: https://www.thedataschool.co.uk/maha-hussari/how-to-2.

I hope this worked out and that it helps you in all your future vizzes! Happy sorting!

Fri 30 Sep 2022

Thu 29 Sep 2022

Wed 28 Sep 2022

Tue 27 Sep 2022