Parameterize a variable in Tableau

Parameterizing variables in your query give your visualizations more flexibility by allowing you to make dynamic selections that are reflected immediately in the visualization. Though there are several ways to do this, the method presented in this topic is one technique that works well.

The following example assumes that you have specified the 1010data query example in Tableau (see Specify a 1010data query in Tableau) and have created the color-coded map (see Create a basic visualization in Tableau). Although this example modifies a previously saved query to parameterize variables within it, the parameterizations could have been done when you originally specified the 1010data query in Tableau.

In this example, you will create a parameter for the division specified in the 1010data query so that you can change the division from within the Tableau workspace without the need to create a separate worksheet or write a separate query for each division.

To parameterize a variable in Tableau:

  1. From the Tableau workspace, click Data > New Data Source.
    The Connect pane is displayed.

  2. Follow steps 2 through 5 in Connect to 1010data from Tableau.
    The Tableau Data Source page appears.

  3. From the Tableau Data Source page, double-click New Custom SQL.

    The Edit Custom SQL dialog opens.

  4. In the Edit Custom SQL dialog, enter the following Macro Language code.
    pub.demo.retail.cookbook.store:{
    <tabu label="Tabulation on Store Master" breaks="divisiondesc">
        <tcol source="divisiondesc" fun="cnt" name="count" label="Count"/>
    </tabu>
    }

    When this query is run, it will connect to the Store Master table and tabulate all the possible values in the column containing the division descriptions (divisiondesc).

  5. Click OK.

    A Processing Request dialog appears while Tableau is loading the metadata.

    When the processing is complete, the Tableau Data Source page is updated to show the Custom_SQL_Query.

  6. Click the title of the data source and enter "Division Codes" as the new title.

    This will help you to easily identify the data source in the following steps.

  7. Click the arrow to the left of the title and select Custom_SQL_Query (1010sql).

    The original data source is displayed.

  8. Hover your mouse over Custom_SQL_Query and click the Edit icon ().

    The Edit Custom SQL dialog appears.

  9. In order to parameterize the variable associated with the division description, highlight the value of the variable in the 1010data query.
    <sel value="(divisiondesc='East')"/>

  10. Click Insert Parameter > Create a new parameter

    The Create Parameter dialog appears.

  11. Modify the values in the Create Parameter dialog.
    1. In the Name field, enter "Division".
    2. Select String from the Data Type drop-down list.
    3. Click the List radio button.
      The List of values section appears.

    4. Click Add from Field > Division Codes > divisiondesc.

      This populates the List of values with the values returned from the tabulation in the Division Codes data source.

    5. Click OK in the Create Parameter dialog.
      The value of divisiondesc is replaced with the <Parameters.Division> variable.

  12. Click OK in the Edit Custom SQL dialog.
  13. From the Tableau workspace, click Sheet 1 to go back to the original visualization.
  14. In the Parameters section on the Data tab, click the drop-down arrow for the Division parameter and select Show Parameter Control.

    The Division parameter control is added to the worksheet.

  15. Click the drop-down arrow on the Division parameter control and select Single Value List.

    The Division parameter control shows all possible values for the division description.

  16. From the list of values in the Division parameter control, select North.
    The map dynamically updates to show those states in the North division that have sales. The states are filled in according to the color gradient to reflect the magnitude of the sales totals.

Congratulations! You now have a truly interactive visualization that allows you to select specific geographic areas, created using 1010data analytics and Tableau visualizations.