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:
- Create a new workbook and connect to the data.
- 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.
- Create a calculated field that will use this parameter. This calculated field will be used in creating the visualizations such as charts and tables.
- Display this parameter on the view. This parameter will be used to select measures to change the values in the visualizations.
- Launch Tableau desktop and create a new workbook.
- 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.
- Create a new sheet.
- 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.