9 Replies Latest reply on Oct 10, 2019 3:18 AM by Ciara Brennan

    Hex Values

    TaRan Wilson

      Is it possible to use hex values in a calculated field to change the color of a chart dynamically? If so, how? I've tried something along the lines of IF [value] = 1 THEN "#FFFFFF", but the color it changes does not match the color I input.

        • 1. Re: Hex Values
          Kaz Shakir

          TaRan,

          Why do you need to use a calculated field to change the color?  In your example, can you just place the [Value] field on the Color tile on the Marks shelf, then Tableau will assign colors to each value of [Value], and you can customize those to whatever colors you need from the color pallet.

           

          For example, just using the super store dataset, If drag the "Category" field to the color shelf like so:

          And then click on the Color tile, and select Edit Colors, and you should see this:

           

          Then you can change the color for each value of category.

           

          Hope that helps.

          Kaz.

          • 2. Re: Hex Values
            TaRan Wilson

            Kaz, thank you for the reply. The reason I cannot assign a value a color is that not all values are present at the time of creation of my dashboard. And if the value isn't present, I cannot assign it a color. See my calculation below.

             

            IF [Due Date] = < -14 THEN "15"

            ELSEIF [Due Date] < -12 THEN "13"

            ELSEIF [Due Date] < -10 THEN "11"

            ELSEIF [Due Date] < -8 THEN "9"

            ELSEIF [Due Date] < -6 THEN "7"

            ELSEIF [Due Date] < -4 THEN "5"

            ELSEIF [Due Date] < -2 THEN "3"

            ELSEIF [Due Date] < 0 THEN "1"

            END

             

            I am tracking the due date of work orders. I work order could be due 15 days from now, but tomorrow it'll be due in 14 days. Today I can change the color of something sitting in the 15 day slot, but not the 14 day because 14 doesn't exist yet. I would have to edit the workbook again tomorrow to get the 14th day, then the 13th, and so on. I want to set it so that the 14th day is automatically set to a certain color, via a hex value, without me having to edit the workbook every day until all values are met (a work order may be completed early, so it potentially wouldn't ever reach day 2 or 1).

            • 3. Re: Hex Values
              Kaz Shakir

              TaRan,

              I see your problem, and that is a bit of a challenging one.  Is there any way for your to create some dummy records in your data?  Ideally you would create 15 dummy records, and each would have a different value for [Due Date], ranging from -1 to -14.  That way you could use that data to set the various colors.  Then save your workbook (and/or publish it to your server), and then go back to your data source and delete the dummy records.  Tableau should remember the settings for the various values of [Due Date] even after you delete those records.

               

              Hope that helps.

              Kaz.

              • 4. Re: Hex Values
                TaRan Wilson

                Kaz, that is exactly what I did it once before. The problem with it is that I don't have access to make that particular change to a dummy record (although I can create a dummy record). I have to get administrative account help from my manager, and last time I asked there were grumblings. I'd prefer not to ask again if I can help it. If I can find no other alternative, then I'll have to go this route again.

                 

                I can't believe that there is no way to assign a hex color to a value via a calculation. I've scoured the Internet with no luck at all. Any mention of "Tableau" and "hex values" always leads me to creating custom colors. Does anyone know of a way to make this work?

                • 5. Re: Hex Values
                  Kaz Shakir

                  TaRan,

                  Here's an idea.  It's not exactly what you want, but perhaps it would work.  First, make sure that the field you are going to place on the Color tile is a continuous field (Green pill, and not a blue pill) - if it's not then convert it to continuous.  Place it on the Color tile, and click the Color tile, and select "Edit Colors."  Tableau will automatically use a "Diverging" color palette, and you can change that to one that suits your needs better.  Then check mark the "Stepped Color" box, and click the "Advanced" button to allow you to set the start, end and center of the range.  Here's an example of what that might look like using a range of -14 to -1, with the Red, Orange, Green palette.

                   

                  Again, it's not exactly what you wanted, but it might accomplish your goal.  Let us know.

                  Kaz.

                  • 6. Re: Hex Values
                    TaRan Wilson

                    Kaz, that actually fixes one of my sheets; I didn't think about turning the pill continuous. I am going to have to create a new custom palate for the colors, but I think that should solve that problem.

                     

                    There is another sheet though that this doesn't work for - I am not able to convert the sheet to continuous. I'm using a different value there (a discrete string). Any ideas to apply a similar fix to it?

                    • 7. Re: Hex Values
                      Kaz Shakir

                      TaRan,

                      On your other sheet, where you are using a discrete string, could you create a calculated field, like you had proposed before, but this time, instead of returning a string value, have it return a numeric value?  Then you can take that calculated field, convert it to continuous, and use that for coloring your chart.  For example, with the Superstore dataset, using the segment field as my discrete string value, I could create the following calculated field:

                       

                      As you can see I included several other potential values for Segment that are not currently in the dataset, so if the dataset were to update in the future and those values show up, they will have a value associated with them.  In my case, Tableau automatically made it a continuous field, but if it does not for some reason, you can do that manually.

                       

                      Is that what you wanted to achieve?

                      Kaz.

                      • 8. Re: Hex Values
                        swaroop.gantela

                        TaRan,

                         

                        I think Kaz has gotten you where you need to go.

                        Not sure if the following link will be helpful,

                        but just thought I'd toss it out there:

                        Show color to Values based on RGB values

                        • 9. Re: Hex Values
                          Ciara Brennan

                          Hi TaRan Wilson

                          If you have time could you please take this quick survey around your Tableau Community Forums experience?...

                          ***Tell us about your experience on the Tableau Community Forums***

                           

                          Much appreciated

                          Ciara

                          [Program Manager | Tableau Community Forums]