Sorting a Multiple Measure Parameter

by Craig Steven

This Blog looks at a problem I had while on a client project where I couldn’t have my graphs sorting change with the parameter I had set up.

The Problem

My issue was with the sorting of a slope graph with the sum of revenue in a specific week compared to the sum of revenue of that same week a year ago. This graph used several different parameters to highlight the best, worst, biggest increase and biggest decrease. When I initially made these parameters the highlighted colours were mixed in with all of the other data points. In this case I wanted my highlighted data points to be at the front rather than hidden away. So on the colour legend I moved the true value above the false thinking this would fix my issue. Nothing changed, which was not what I was expecting.

From what I understand the sorting wasn’t changing between the different calculations built into the parameter. When the parameter was changed it wouldn’t sort any differently because it didn’t have the new values that needed to be sorted and the field that it had been set to sort by hadn’t changed so neither did the sorting.

How I fixed the Problem

The solution was to create a calculated field that would change what field is used for the sorting calculation in the view. Pictured below is that calculation which is very similar to a typical calculation used one of the steps to implement a parameter into a graph. In this it is important to remember that with each measure for my case I was looking at the best and worst so I needed to turn some into negative numbers so when sorted the worst values would be seen as values that needed to be sorted first. It is also worth mentioning that any non-aggregated values need to be aggregated at this point else firstly the calc wont work as you will be sorting by each row and not summing to your desired granularity.

Once I had made the calculation I implemented it into the sorting of the graph by selecting the dimension and sorting. Then sorting by field and on the drop down finding the calculated field. So when sorting it tells tableau that when the parameter is [1] then sort by -sum of my first measure calculation and so on. With the end result looking like bellow.

I hope this blog is helpful for someone with this niche problem in the future but regardless having this issue and learning how to solve it really helped my understanding of how the sorting functions work in tableau.