How to dynamically generate a chart based on measure selection

Depending on the business requirement, sometimes you may have lot of key measures in your data. In such situation, you have a choice to – create separate chart for each measure or to create one chart and change the chart dynamically based on the user selection of measures.

In this blog, i will discuss, how to dynamically generate a chart based on user selection of measures. You may also want to look how-to-display-charts-based-on-a-selection-in-tableau.

Steps to dynamically generate a chart based on user selection:

  1. Create a new workbook and connect to the data.
  2. Create a parameter – datatype as string. Select “Allowable Values” as “List” . Under the “List of Values” specify the “Value” as the name of your measure or calculation.
  3. Create a calculated field that will use this parameter. This calculated field will be used in creating the visualizations such as charts and tables.
  4. Display this parameter on the view. This parameter will be used to select measures to change the values in the visualizations.

Example exercise

  1. Launch Tableau desktop and create a new workbook.
  2. Connect to sample datasource Superstore.xls. To learn how to connect to excel datasource visit Connecting to excel datasource in Tableau. This datasource comes with your Tableau desktop download. I will use the “Orders” sheet available in this datasource.
  3. Create a new sheet.
  4. Navigate to the “Measures” in the data section on the left. Right click and select “Create parameter’


5. Create a Parameter using the settings in the below screen. This parameter will contain the measures you want to use in the selection. Make sure that “Value” under list of values contains the exact measure names.

6. Right click again on the “Measures” section and select “Create Calculated field”. Name this field as Calc_Measure_Name and use the below calculation

Case [Param Measure Selector]
When “Profit” then [Profit]
When “Quantity” then [Quantity]
When “Sales” then [Sales]

7. Now create visualization of your choice. For this example, i will drop “Segment”  to the Columns shelf and Calc_Measure_Name on the Rows shelf. Tableau will automatically create a bar chart, if not then select one from “Show Me” option on the right.

8. Right click on the empty space on the view and select the parameter created in step 5

9. This parameter will let you make selection on the measures. Bar chart will change according to the measure selected.


2 thoughts on “How to dynamically generate a chart based on measure selection

  1. Hi Chandraish

    This is a very good topic to visualize the data in a partitioned way, I have one question in Param Measure Selector,

    Can we select multiple data types for list of values in a single Param Measure Selector field, as per this topic i selected 3 string values profit, sales, Quantity, If i get the requirement to select the Date or number field then Tableau allows to select different data type variables in list of values or we need to create one more Param Measure Selector?

    • Yogesh:
      Let me explain this with the requirement of this article. The requirement is to allow users to select a Measure. This selected measure will get changed in the chart.

      Parameter can have only one data type at a time. Because there is only one parameter. In this case only one parameter “Param Measure Selector” is created and it is of type String.
      It is of type string because it is holding measure names, Profit,Sales and Quantity. Profit,Sales and Quantity are measures and contains numeric values.
      Though it doesn’t make sense, but If for any reason you want to include “Order Date” in the parameter, it will also be string type but if used in the “calculated field” with other measures, it will throw an error as others are measures/numeric and Order Date is dimension/Date .
      If you have to use “Order Date” with other measures in this parameter, convert Order date to Measure. It can be done by right clicking and selecting “Convert to Measure”. Now Order date can be used in the calculated field with other measures.
      A better use case will be, to give users option to select Dimensions and change the Dimensions in the chart.
      For this, create a new a Parameter,say “Param Dimension Selection”. This parameter will also be of type string as it will hold values like Order Date,Segment,Region etc.
      use this parameter in the calculated field. To use Order Date in the calculated field with other dimensions, change it’s data type to “String”

      Hope this answers your doubt.

Leave a Reply

Your email address will not be published. Required fields are marked *