Example: Add a Parameter to a Map View

This example uses the World Indicators sample data source to demonstrate the following:

  • How to build a map view that shows the birth rate for each country in the world.

  • How to create a calculated field that distinguishes countries/regions with a low birth rate from those with a high birth rate.

  • How to create and display a parameter so that users can set the threshold for low vs. high birth rate.

Build a map view

  1. In the Data pane, double-click Latitude and then Longitude.

    Tableau puts Longitude on Columns, Latitude on Rows, and displays a map of the world.

  2. Drag the Year dimension to Filters.

  3. In the Filter Field [Year] dialog box, choose Years and then click Next:

  4. In the Filter [Year of Year] dialog box, select 2012 and then click OK:

  5. Drag the Country dimension to Detail.

  6. Set the Marks type to Map:

  7. Drag the Birth Rate measure to Label.

You now have a map that shows birth rates for countries/regions around the world:

You can zoom the map or hover to see a tooltip for any country.

Create a calculated field to set a threshold

Next, you'll distinguish a low birth rate from a high birth rate.

  1. From the top menu, select Analysis > Create Calculated Field .

  2. Name the field High Birth Rate and type or paste this calculation in the formula field:

    IF ([Birth Rate]) >= 0.014 THEN "High" ELSE "Low" END

    The value 0.014 is equivalent to 1.4%. The range of actual values that we can see on the map range from below 1% up to nearly 5%.

    When you click OK to apply and save this calculation, Tableau categorizes it as a dimension.

  3. Drag High Birth Rate to Color.

    The map now shows low birth rate countries/regions in one color and high birth rate countries/regions in another:

    But the definition of high birth rate as anything equal to or greater than 1.4% is arbitrary—that value was chosen because it divided the world's countries/regions about evenly.

    Instead, you can let users define that threshold, or give them a control that they can use to see how changing the threshold changes the map. To do this, you create a parameter.

    Create a parameter

  1. Right-click (control-click on a Mac) in the Data pane and select Create > Parameter.

    Note: If you clicked on a field on the Data pane, some fields might be filled. You can just change the fields as needed.

  2. In the Create Parameter dialog box, name the new parameter Set Birth Rate and configure it as shown:

    For information on the fields in the Create Parameter dialog box, see Create Parameters.

    Because the Data Type is Float, the parameter control, when you display it in the next procedure, will be in the form of a slider. This is because floating point values are continuous—there are an infinite number of possible values.

    The Current value sets the default for the parameter: 0.019 is 1.9%. The Range of values section sets the minimum and the maximum values and the step size—that is, the least amount by which the value can change.

  3. Click OK .

Create and display the parameter control

Now you must connect the parameter to the High Birth Rate field.

  1. Right-click High Birth Rate in the Data pane and select Edit.

  2. Replace the hard-coded 0.014 value in the field definition with the parameter name:

    IF ([Birth Rate]) >= [Set Birth Rate] THEN "High" ELSE "Low" END

    Then click OK.

  3. Right-click the Set Birth Rate parameter in the Data pane and select Show Parameter Control.

By default, the parameter control is shown on the right. Now you and users of your view can raise or lower this value incrementally to see how changing the definition of "high birth rate" affects the map.

Thanks for your feedback!Your feedback has been successfully submitted. Thank you!