12 Replies Latest reply on Feb 17, 2020 4:10 AM by Matt Beasley

# Fixing Colours to a Top 5 Pie Chart

Hi all,

I have a pie chart on my workbook that filters specifically to the top 5 most recurring errors out of a pool of 500+ different errors:

If I was to apply a filter for say the category the error falls into, the colours would change based upon the new top 5 most recurring errors for that category as such:

As I have 500+ errors and I am only limited to working with a certain amount of colours, it is next to impossible to have them all different colours/shades so I'm conscious of having the same/similar colour for two different segments of the pie chart appear next together and hence look indistinguishable.

My question is - is it possible to assign a specific colour for each rank of the top 5 entries that will appear consistently in the pie chart?

I.e. - The most recurring error on the pie chart will always be dark blue regardless of what filter is applied
- The 2nd most recurring error on the pie chart will always be light blue regardless of what filter is applied
- The 3rd most recurring error on the pie chart will always be light green regardless of what filter is applied etc etc...

Hope this is clear.

Thanks

• ###### 1. Re: Fixing Colours to a Top 5 Pie Chart

Hello Matt,

You can use this calculation on color. Just pass in your measure instead of Sales"

if RANK(sum([Sales])) < 6 then RANK(sum([Sales])) end

Hope this helps! See Attached.

Robert Breen

1 of 1 people found this helpful
• ###### 2. Re: Fixing Colours to a Top 5 Pie Chart

You can create a calculated field using the RANK function and use that to color the top 5 values.

Here is what I have written in the calculated field: RANK(SUM([Sales])).

Hope this helps.

1 of 1 people found this helpful
• ###### 3. Re: Fixing Colours to a Top 5 Pie Chart

Hi Hari,

Apologies for the delay in response.

I've tried this approach but sadly it hasn't worked for me.

Tableau seems to think my measure isn't broken down so it just reckons there is 1 value and hence 1 rank so the pie chart is just returned as one fully coloured circle.

Is there anything I might have missed?

Cheers,
Matt

• ###### 4. Re: Fixing Colours to a Top 5 Pie Chart

Hi Robert,

Apologies for the delay in response.

Like with Hari's method, I've also tried this approach to no success.

My measure doesn't look like it's been broken down by type and so it just reckons there is 1 value and hence 1 rank so the pie chart returned is one fully coloured circle.

Any suggestions as to what I might be missing?

Cheers,

Matt

• ###### 5. Re: Fixing Colours to a Top 5 Pie Chart

Hello Matt,

The problem is probably from the table calculation direction. Here's how I have mine set. Image below. If yours is more complex, you may need to adjust which dimensions are checked.

Are you able to upload your twbx file? i can set it up for you.

Robert

1 of 1 people found this helpful
• ###### 6. Re: Fixing Colours to a Top 5 Pie Chart

Hi Robert,

This has worked a treat - thank you very much!

I have one final question if its possible - is there any way I can edit the names of the colours in the key to show the name of what is present in a way such that any filters applied will change the name on the key?

Thanks

Matt

• ###### 7. Re: Fixing Colours to a Top 5 Pie Chart

Hello Matt,

You can use this calculation to do that.

if RANK(sum([Sales])) < 6 then str(RANK(sum([Sales]))) + " - " + str(attr([State])) end

Hope this helps! See Attached.

Robert Breen

1 of 1 people found this helpful
• ###### 8. Re: Fixing Colours to a Top 5 Pie Chart

Hi Robert,

This has successfully changed the key, thank you very much but sadly now the colours are not locked and are changing when filters are applied (can't win can I? Haha)

Is there any way to make both work simultaneously?

Sorry to be a pain

Cheers,
Matt

• ###### 9. Re: Fixing Colours to a Top 5 Pie Chart

Hello Matt,

I would use two sheets for this instead of a legend. You can make a sheet look like a legend. See attached. I used the original rank as color, and the rank with state as a row in the second sheet.

1 of 1 people found this helpful
• ###### 10. Re: Fixing Colours to a Top 5 Pie Chart

Make sure you line up your colors. See attached.

• ###### 11. Re: Fixing Colours to a Top 5 Pie Chart

Hi Robert,

Think I am pretty much there - thank you so much for your help!

I'm pretty sure this will be my last question - I've done this key on a separate sheet as advised above but when applying a filter x amount of my top my top 5 disappear depending upon that is filtered.

I've tried adding the DVC Description filter I've used to set up the top 5 highest counts to context but that doesn't seem to have affected anything.

Is there anything I can do to rectify this?

Thanks,
Matt

• ###### 12. Re: Fixing Colours to a Top 5 Pie Chart

Hi Robert,

I've actually figured this out now. Just needed to exclude anything outside top 5 on the key.

Thanks again for all your help!

Matt