Is it possible to sort series items in a legend by count?

  • 26 October 2018
  • 3 replies

Nothing beats a picture…

Default is alphabetical left to right for this particular chart. You can sort the stacked chart but can you also sort the legend?

Similarly can you selectively enable only the highest count series item in the legend so that when the chart loads only that series item is selected allowing the user to manually select additional series items?

Thanks in advance.

3 replies

Userlevel 1

Hey @jkmajcen,

I hope all is well! Regarding the option to sort the legend, this functionality is currently unavailable; however, I was sure to relay this to the product team on my end. If the categories in your current legend are the results from a dimension being pivoted, then you could redefine that dimension with the case parameter. The order in which we define the values in a case LookML expression will coincide with the order in which the values are displayed in the legend. There is more information about this method here.

If the categories in the legend are the results of several different measures, as opposed to a pivoted dimension, then we could re-arrange the measures in the results table to correspond with the order in which we would like the series to be represented in the legend. Notice that how the measures are ordered in the examples below is reflected in the legend:

In terms of the last question, we can hide a series in the legend by selecting it. When we click on the series name in the legend, it will grey it out and also will hide it from the visualization. With that said, we can deselect all of the series in the legend except for the series with the highest count and can save this as a Look like so:

When users load the Look, it will look like the above image by default but users will also have the option to select the different legend options to include them in the visualization. For example:

Let me know if I can clarify anything about this on my end! Hope this helps!



Thanks for the info. The categories in the legend are the result of different measures. I will explore the info you provided.

Also, on the select only a single legend option. Can this be done dynamically based on a condition? In this case, I’d like to select the legend option with the highest count.


Userlevel 4

Hey @jkmajcen

That’s a cool idea, totally makes sense! At the moment, the legend to be pre-selected by default would saved with the Look, so we wouldn’t be able to dynamically pre-select. I’ll definitely pass on the feedback.

One other option might be to create a table calculation that returns yes for values you want to display and no for those outside of your condition - something like if(value>100, yes, no) - then we can “Hide No’s From Visualization” - this would filter out rows that don’t match the condition, hiding them from your legend entirely, rather than just deselecting them.