How to create and use parameters in Tableau Prep
Parameter is simply a global placeholder value such as a number, text value or Boolean value that can replace a constant value in a flow.
In this short article, I am going to demonstrate how you can create and add a parameter both at the input and output steps of your flows.
Let’s build a case first
Let’s say you created a flow to prepare and clean a certain dataset, and you would like to reuse the same flow with the same schema to prepare other related datasets. Rather than creating multiple flows for each data, you can create a single flow and use a parameter to run the same flow with the different datasets, while exporting the clean data in different file type names.
Note parameters can be applied to file names, paths, table names etc. In this example, I’ll be applying a parameter to a file name to select different dataset for the flow.
For practice purpose, I’ll be working with these four datasets namely, East Superstore, West Superstore, South Superstore & Central Superstore.
(The above flow is used to clean and aggregate sales, profit, orders, discount, and quantity by States for the ‘East Superstore’ dataset)
And therefore, instead of replicating the same flow to clean and aggregate the data for West, South and Central regions, you can just create a parameter and use it in the input step to load different dataset in the same flow.
Let’s create a parameter
To create a parameter, select the parameter icon on the toolbar.
Next create a string parameter, to be used in selecting different data files for the flow - as well as exporting the clean data in different file type names.
(Using this parameter, you can easily choose a different dataset for the same flow, as well as export the clean data into a different file type name).
Add the parameter in the Input step
Since all the file names I need to clean are similar, apart from they have the ‘Region’ name. see below.
All I’ll do is go to the input step and replace a section of the file name with the parameter. See the section highlighted below.
Replacing the region part on the file name with the parameter we’ve.
Add the parameter in the output step
Repeat the same on the output step, whereby in this case am going to export the clean data in this format, ‘Region – Superstore (clean data)’ – Meaning when the selection on the parameter is ‘West’, then clean data will be exported as ‘West – Superstore (clean data)’
With now the parameter ready, one can clean the different datasets without necessarily creating a new flow. For example, to clean the ‘South-Superstore’ data, all I need to do is select ‘South’ on the parameter – and automatically this data will be loaded in the flow and ready to be exported as ‘South – Superstore (clean data)’.
Select run the flow, and on the pop-up box, select ‘South’ - the region’s data we’re cleaning.
Running the flow will export the clean data file name as ‘South – Superstore (clean data)’, as show below.
I hope this article was helpful to you. To receive more of the Tableau tips and tricks, kindly join our mailing list by subscribing below.
Thank you for reading.