Grouping Dimensions by Rank

Basically I have a dimension that has many values and I want to make a pie chart that includes the top 5, 10, etc and then groups the rest into it’s own value of “All Other”. How would I do this?

0 3 3,058
3 REPLIES 3

Hi @mjgrier,

The one option would be to create a case when where we change the dimension such that we only show the individual values for the top n values, then group everything else as other. Then, we can just select this dimension in the explore and select the corresponding measure. 
 

f2aae3b1-2331-4774-a227-b236eb766334.png

We could use the same principle with a custom dimension. Instead of a case when, we would want to use an if statement. 

aed8b91d-1c0d-4f30-890a-55c426e4d446.png
b8c6eba1-d40d-4b1c-9de3-39fb453a1573.png



If you do not have LookML or custom field access the alternative would be to use a series of table calculations. We can use an if statement where we show the individual value based on the row (in my example I sorted by count descending). Then, if it above a specific row number, I use a sum and a list offset function to aggregate the other counts. 

 

e8812776-49b5-4982-9fa8-5faed503bedc.png



I then need to change the label of the state after it exceeds my row threshold. I can use another case when to do this. 

700fdce4-f61f-4e94-98cb-ee66f35fcfc9.png



Finally, I need to hide the rows that I do not want to show and I use a third table calculation with an if statement that returns a yesno value. Then, I click the gear icon on this column and select Hide No’s from Visualization. 

1d85632f-7df4-47d8-adf7-c580e692f193.png
c9a67637-78eb-43b2-bdf2-646787d90780.png

Please let me know if you have any questions.

Thanks,

Eric

Hey Eric,

Thanks for the reply, I need this to change dynamically as the top 10 will very likely change on a month to month basis, so I think the best course of action would be the table calculation route correct?

eric_h
New Member

I think the table calculation route that Eric mentioned is the easiest to implement, but you can also add Top N analysis to your LookML, as well!

There’s a great article that shows how you can dynamically select the top 5, 10, 15, however many you want, while packing everything else into an “Other” category. It’s essentially doing the same thing as the table calculations, but packs that information into derived tables within your model.

He does a great job explaining it with code examples, so I won’t plagiarize it here 🙂

Top Labels in this Space
Top Solution Authors