Tableau Parameters: How to Set up Default Values

by Ben Connor

A pretty common use case for stakeholders when viewing a Tableau dashboard on Tableau Server/Cloud is to have the default value of a certain parameter or filter update based on a given metric.

For example, they might want your view to always filter to the state which has the highest sales or filter to a particular user depending on who is viewing the dashboard.

This is something that’s possible to do using parameters, although it’s not immediately obvious how to set this up in all situations.

Creating the Default Value:

First let’s take our sales by state as an example - let’s say that the dashboard needs to be set up so it defaults to view the state with the highest sales every time the dashboard opens but then after that the user is free to select whatever state they want. This can’t be done with a normal filter on state, the default value will be whatever the dashboard is published with as Tableau won’t be considering the sales of each state in this case.
To filter to our top sales state, first we will have to find what state that is and what value it has for sales. To do that we can make a simple table with ‘State’ on rows and ‘Sales’ on the text shelf and sort descending.

Sales by State (Sample Superstore)

We can see that California is by far the top state with $457.69K in sales. We now have to create a calculation that will return only the sales value for the top state (in our case this is currently $457.69K). This requires the following nested level of detail expression:

{FIXED : MAX( { FIXED [State/Province]: SUM( [Sales] ) } ) }

The inner portion of this LOD:

{ FIXED [State/Province]: SUM( [Sales] ) }

Finds the sum of sales for each state. This is then wrapped in a further LOD which finds the max value of the previous calculation in the whole dataset. We can see what this is doing by dragging this new LOD calculation onto our table next to the existing sum of sales.

Our LOD only returns the sum of sales for California in each row

As we can see, this calculation is independent of what we have in the view (this is important for later) and only reflects the sales value for California.

Now we have our top state sales, we can use this to create a field which will only generate the name of the state which corresponds to this top sales value.

This can be done with a fairly simple if statement but it does have a small nuance:

{ FIXED : MAX(

IF [Max State Sales LOD] =  { FIXED [State/Province]: SUM([Sales]) }

THEN [State/Province]

END

)}

The main part of this expression is the IF statement which just says that if our max sales LOD from before is equal to the sales of a particular state, then return the name of that state.

The extra part that is important for this use case in particular is that this whole expression is wrapped in an LOD of { FIXED : MAX( <expr> )}.

To see why this is important we can look at the tableau parameters documentation:

Taken direct from Tableau's documentation

https://help.tableau.com/current/pro/desktop/en-us/parameters_create.htm

Essentially, for use as a parameter’s default value, your calculation has to return a single value and be independent of what is in the view - hence the need for an LOD, Tableau needs this single value to know what to use as the default. You can see what different the extra nested portion of the LOD makes below:

Difference between nested LOD and non nested LOD

The extra { FIXED : MAX( <expr> )} makes the calculation fixed across the whole dataset (i.e. single value and view independent) whereas without this you can see it will return nulls for all states that are not California.

Creating the Parameter:

The last thing we need to do is create the actual parameter and use it to filter the visualisation. The easiest way to do this is right click on the ‘State’ field and go to Create -> parameter to display a parameter with a list of all values for state loaded in.

You should now be able to change the ‘Value when workbook opens’ to your newly created calculated field!

Change the 'Value when workbook opens' to your new calculation

Then all you have to do is create a quick filter based on your parameter such as below:

Simple filter which filters to the state selected in your parameter

Add this calculation onto the filters shelf of your visualisation and check the box for ‘True’ and your view should be filtered to the top state for sales, you can test how this works by changing the value of your parameter to a different state and then saving and closing your workbook before re-opening.

Regardless of what you changed your parameter to before closing it should re-open with your default value selected.

Example map of Sales by State with the default value filter applied

I hope this helps!