Sorting Stacked Bar Charts Using Set Actions.

In this write up, I showed how to sort stacked bar charts using parameter action. I did this because I could not wrap my head around sets and set actions at the time so parameters were always my go to.

However, in todays update, I am going to show you how to sort stacked bars with a set action because I discovered they are simpler. Lets dig in.

Using superstore data, let's create a stacked bar chart by moving sales to row, order date to columns and segment to color.

The problem with stacked bar charts is that apart from hovering on the bars, we cant really tell how much sales accrues to the corporate and consumer segments in orange and blue respectively. Due to this we cant also compare how these segments are doing per year unless we hover.

Using sets and set actions together, we can lessen this difficulty so that whenever we click on a segment, the segment falls to the bottom giving all years an equal start point. First thing to do is to right click on segment and create a set.

In the set, tick consumer.

Create a calculated field called sort and drag into it the segment set.

Now drag your segment set unto details in the marks card and show set.

Click on segment dropdown and select sort which brings up the sort window. In the window, sort by field, ascending, using the sort calculated field and set aggregation to minimum.

This allows the segment set to switch segment positions to the bottom.

Create a set action to update the selected segment in the set by clicking on its portion on the bar.

Click on worksheet, actions which brings up the action window. In the window click on add action, and change set values.

This brings up a new window to add set action. Give it a name, select the sheet, run on select and single select only, select the target set, let running the action assign values to set and clearing selection keep set values. Don't forget to click ok.

This then allows positional switch by clicking on the bars however we observe the bars are highlighted upon clicking and that could be taken out by creating a simple string calculation.

Put this calculation on detail and connect it with the highlighter by clicking on the highlighter above and selecting 'd'. This disables bar highlighting.

Author:
Michael Apau
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab