Search code examples
tableau-apitableau-desktop

Creating index chart with tableau


I am trying to recreate an index chart with Tableau (https://mbostock.github.io/protovis/ex/index-chart.html) for Makeover Monday 2021 W17 data set, and I cannot figure out what is the best approach to do this. I am using Tableau Public so I cannot attach the workbook as a document but you can find it here : https://public.tableau.com/views/RemakingMakeoverMondayW17IndexChart/Sheet14?:language=en-US&publish=yes&:display_count=n&:origin=viz_share_link

The data set contains every state in the US and a price index for that state between the years 2008-2019. I want to create a line chart which would use a selected year as a comparison condition, and would show the difference between each year and the selected year.

My approach was the following:

  1. I created a parameter for date "Year Parameter".

  2. I created a calculated field "PARAMETER YEAR" to give me price index for the selected parameter date:

IF [Year] = [Year Parameter] THEN [Price Index] END

  1. I tried to calculate the difference and that is where I get stuck: SUM([Price Index]) - SUM([PARAMETER YEAR]). This calculation shows me only 1 state for the selected year.

Any ideas on how to deal with this?


Solution

  • try this for your reference index:

    {EXCLUDE [Year], [Regions], [Description]   : sum(
        IF DATEPART('year', [Year])= DATEPART('year', [Year Parameter]) THEN [Price Index]
             ELSE 0   
    END)}