14 Replies Latest reply on Mar 9, 2016 2:11 PM by Jenny Sanders

# Distinct color values for different product id's

Hi

I am trying to color code the "Product_id"  i.e. I am trying to get one separate color for each product id's that i have in my data depending on the Color_value attached to it.

So I created a LOD to get the total price product and based on the total I want to give a color. The field i am counting is Product_id.  So the calculated field I am tryimh to use is

if the "total_price" =  8 then "Red"

elseif "total_price"=7 then "green"

elseif "total_price"= 5.5 then yellow

end

When I try to use the Color_value field in my calculated field it automatically turns into a count  and I only get one unique color.

I have attached a dummy workbook with my approach so far. Can anyone please tell me what is wrong with my approach?  The "total_price" gives the sum of price / product. "Total_price_color" is the calculated field i want to create.

• ###### 1. Re: Distinct color values for different product id's

Hi Jenny,

You could drag Total Price (not Total Price Color) to the color mark, and assign a color palette there.  Would that work for you?

edited to add:  Well, you could also change your formula to this:

IF INT([total_price])=8 THEN "red"

ELSEIF int([total_price])=7 then "Green"

ELSEIF  int([total_price]) =5.5 THEN "Yellow"

END

Then drag that onto the color mark button, and change it from Measure to Attribute.  For some reason, the attribute for Yellow comes in as Null instead of Yellow, but this provides a good starting point.

-Ann-

1 of 1 people found this helpful
• ###### 2. Re: Distinct color values for different product id's

Jenny,

IF FLOAT([total_price])=8 THEN "red"

ELSEIF FLOAT([total_price])=7 then "Green"

ELSEIF  FLOAT([total_price]) =5.500 THEN "Yellow"

END

Drag that to the color marks button, and change it to Attribute instead of Measure.  Then you will be able to get the color selection the way you want it.

1 of 1 people found this helpful
• ###### 3. Re: Distinct color values for different product id's

Hi Ann,

Thank you so much.

I edited the formula and did exactly the same way. But I am still getting one color bar.  I would really appreciate if  you could  please post a workbook with the changes mentioned.

J

• ###### 4. Re: Distinct color values for different product id's

Hi Ann,

Sorry for the last comment to post a workbook. It would be really helpful , if you make those changes in the attached DummyData workbook.

Thanks !

• ###### 5. Re: Distinct color values for different product id's

No worries about asking for a workbook - it's a good thing to be able to deconstruct things sometimes.   I've attached a workbook called Int and Float that has the all the formulas I had in earlier messages.  This also has  a crosstab and a chart showing how the colors appear between the two types of visualization.

I hope it helps!

-Ann-

• ###### 6. Re: Distinct color values for different product id's

thanks Ann !

• ###### 7. Re: Distinct color values for different product id's

No problem Jenny, I was glad to help.

• ###### 8. Re: Distinct color values for different product id's

Hi Ann,

Another question for you. Is there any way that I can show all 3 distinct color per product id in a single bar?

I mean that I have similar data for 5 years . The requirement is to count the product id's per "total_price" value and then show them with different colors for each year. I am not sure if I am able to make you understand.

I have attached the same workbook with some additional data and how the view should look like as per the client req. They want to view like that way.

I just want to know if this is even possible to do the way i want it to be?

Thanks !

• ###### 9. Re: Distinct color values for different product id's

I'm not sure I understand either, but.... would dragging Product ID onto the color mark get you what you want?

• ###### 10. Re: Distinct color values for different product id's

Oops. I meant drag year onto the color mark.

• ###### 11. Re: Distinct color values for different product id's

Hi Ann-

Bothering you again with this requirement! . I tried a couple of things over the past couple of days but nothing seem to work out. "total_price_ind" would indicate the distinct product id's and show them as color. i mean to achieve something similar to the attached workbook. In the wokbook if I drag "class" to the color shelf then it shows "distinct count of the product id's" based on "class" . I want the similar thing but based on "total_price" i.e. if total_price = 8 then it will count the distinct no. of product id's and show them as a color "red" . Whenever I'm dragging the "total_price_color " the color doesn't appear.

Let me know if this helps! I have attached the workbook.

Thanks J!

• ###### 12. Re: Distinct color values for different product id's

Hi Jenny,

I'm still scratching my head on this one - it's deceptively easy, and I feel like I've done something like this before.  I've not forgotten you, and am tinkering with it at the moment (I've just been a little busy).

-A-

• ###### 13. Re: Distinct color values for different product id's

I spoke too soon.  I think I've got it.

Is this what you're looking for:

How I got this:

Put a continuous count of Product ID on rows.

Put class in the marks shelf, not on any of the buttons.

Drag Total Price color into the Marks shelf, it will probably default to sum.  Double click on the shelf to edit, and change Count to ATTR.

I've attached the workbook, but it's in Tableau 9.1.1, and I received the older version will be upgraded message when saved when I opened yours.

-Ann-

• ###### 14. Re: Distinct color values for different product id's

Hi Ann---

Sorry for being "so late" I was busy in other stuff. This completely solved my problem.

Thanks !

J