2 Replies Latest reply on Oct 23, 2019 4:30 PM by Daniel Lee

    How do I change colors for part of the bar chart based on date?

    Daniel Lee

      Hi,

       

      I am using Tableau version number 2018.3.5 Desktop Professional edition. I attached the workbook "demo_20191023.twbx" to this post.

       

      In "demo_20191023.twbx" "Sum Bar Chart" sheet, I have a bar chart as shown below:

       

      sum_bar_chart.PNG

       

      Here's what I want to do:

      • For dates 8/16/1990 and after, I want the option to change the colors for A and B. For example, I want the option to change all the dates 8/16/1990 and after to be yellow and purple.
      • I want a checkbox to be able to do this. The checkbox can be labeled something like "change color for dates 8/16/1990 and after" or something like that. If the checkbox is checked, the bars for 8/16/1990 and after will be yellow and purple. If the checkbox is unchecked, the bars for 8/16/1990 and after will be the same color as the bars before 8/16/1990.

      Can someone show me how to do this? Description of steps as well as attaching a workbook would be most helpful. If attaching a workbook, please remember to use Tableau version number 2018.3.5 because I won't be able to open the later versions of Tableau.

       

      Any help would be greatly appreciated!

        • 1. Re: How do I change colors for part of the bar chart based on date?
          Bob Scharf

          Hello!

           

          I think I'm understanding the request and have attached a workbook. Here are the steps that I took:

           

          1. Create a Parameter named "change color for dates 8/16/1990 and after"
            1. Data type = String
            2. Current value = Yes
            3. Allowable values = List
            4. List of values (Value, Display As) = {(Yes, Yes), (No, No)}
          2. Create a calculated field Color, formula =

                    if [Date] < DATE("1990-08-16") AND [Variable1] = 'A' then 'A - Before 8-16-1990'

                    elseif [Date] < DATE("1990-08-16") AND [Variable1] = 'B' then 'B - Before 8-16-1990'

                    elseif [Date] >= DATE("1990-08-16") AND [Variable1] = 'A' then 'A - On or After 8-16-1990'

                    elseif [Date] >= DATE("1990-08-16") AND [Variable1] = 'B' then 'B - On or After 8-16-1990'

                    END

           

              3. Create a calculated field Show Color, formula = if [change color for dates 8/16/1990 and after] = 'Yes' then [Color] else [Variable1] END

              4. Put the Show Color calculated field on the Color in your Marks

              5. Put Variable1 as a detail in the Marks

              6. Right click on the new parameter and click 'Show Parameter Control'

              7. This should allow you to change the parameter from Yes to No and the bar colors will update appropriately.

           

          Hopefully this helps, let me know if you have any questions. Thanks!

          Bob

          1 of 1 people found this helpful
          • 2. Re: How do I change colors for part of the bar chart based on date?
            Daniel Lee

            Thank you so much for the quick reply Bob! This is exactly what I was looking for.