in this video we will talk about parameters we will talk about what parameters are and how to use them in order to understand parameters better we will go over 10 common use cases and introduce tips and tricks and common constructs like case and if else statements parameters are often confused to being similar with filters we will break down the differences lastly we will introduce parameter actions i'll see you in a bit i have added chapters in the description down below if you want to jump to specific topics i hope you will consider watching the whole video though as there may be some new topics or new concepts or new tips and tricks that you may find useful let us start with some definitions in tableau's documentation it defines a parameter as a workbook variable such as a number date or string that can replace a constant value in a calculation filter or reference line there are a few important things to note here a parameter exists at the workbook level which means it can be seen and used across your workbook this is important because this means you don't have to recreate parameters for each worksheet there is also mention of a variable a variable is a term used in programming which refers to a placeholder for a value and that's what a parameter is it holds a value that can be used to replace something that is referenced in places like a calculated field a filter a reference line and a few others the definition in the cambridge dictionary is also helpful in understanding what parameters do in here it highlights that parameters can establish or limit how something must happen or how something can be done as far as tableau is concerned a parameter is a field similar to all the fields you see in your sidebar but it's one that can accept input usually from your end users and the values that it accepts can change how your charts or dashboards behave it's just like ordering the parameter can ask our end users what would you like and the answer can vary from user to user and depending on what our end users say what gets prepared would be different now that we have defined parameters let's move on to the typical steps we follow when we use parameters please note that all of these will be demoed later on the first step is to create our parameter second we may opt to show our parameter control there will be times when we may decide not to show the control at all and simply use the parameter for some background calculations third step we may need to create a calculated field but note that this is optional as well this will really depend on how we intend to use the parameters there are certain use cases that don't require the creation of calculated fields and fourth we need to use the parameter the last step is important to remember parameters by themselves don't do anything or affect anything we still need to use this parameter somewhere in our worksheet for it to affect something in other words we need to wire it in let's jump to tableau and look at some initial use cases for parameters let's start with looking at filtering for top n and i will show you two ways to do this for the first use case if we simply wanted to show the top records in our view in this case let's say top 10 customers top 20 customers one of our options is to simply go to our discrete field and from here choose filter in the filter window there is a top tab and from here we can select buy field by default this selects top 10 but we can create a parameter from here so when you click on the drop down there is an option to create a new parameter when we select this option this gives us the create parameter window in the create parameter window we can specify the name of the parameter by default because this is a top n tableau already selects an integer for us with a current value of 10 and a range of values from 1 to 100 so let's click on ok first and click on ok again let's also rename our parameters i'm just going to right click rename i'm going to call this top n and let's also show the parameter so right click on this parameter and then show parameter so right now this gives us top 10 but should we decide to change it i can move this lighter and the view will change based on my input now with top ends and especially relative top ends there are special considerations when you have multiple filters i do have another video on filters that discusses this in more detail i will link it up in the card above in description down below if this is something that you will find useful now let's delete this parameter and introduce the creation a different way so let's delete this instead of going through the dimension we are going to explicitly create our new parameter so on the drop down create parameter this gives us a very similar window to what we have just seen so let's create a new parameter again let's call this top n we can choose our data type so in this case still an integer maybe the current value is 10 as well for the value when the workbook opens for different kinds of parameters we may want this to draw from our data source but for our purposes right now we're going to leave it as is we can also decide to change the display format right now for our purposes we're going to accept the default now for allowable values all usually means a text box which means we can just type in the value that we want we can also decide to type in a list of values and it will be shown as a drop down or we can also specify a range of values and by default this is going to be shown as a slider i'm going to leave this as all for now it's going to be a text box it's going to be free form and it will accept any valid numeric values let's click on ok let's right click and show the parameter remember this parameter does not do anything until we wire this in so even if i change this to five it will not do anything to our workbook we need to use this in our worksheet to affect some kind of change now in this case i'm going to click on the drop down on customer name under filter and top by field from here we can select the new parameter that we just created so select top n click ok so now we have top 5 because that's what we have selected but should we change this to 10 you should see your view change as well we change this to 20 will change as well another way we can create a top n is by using table calculation functions there are different functions we can take advantage of but in this demo we are going to use a function called index the index function simply gives us a sequential number in this case i'm going to double click on an empty area in the markz card and type in index i'm also going to convert this field to discrete because i want to show this as a column in the rows shelf so on the drop down discrete and then move this to our row shelf now the last thing we need to do is to only show the records that are within our selected top end and this will require that we create a calculated field so let's create a calculated field on the drop down create calculated field and in here let's type in a name in top n and we simply want to know if this index is less than or equal to our selected top end parameter let's click ok let's drop this new field into our filter shelf and only leave the records for when it is true so let's click on ok and ok again in here we can also decide to hide our index column so on the drop down uncheck show header and this is our top 20 customers when we change our parameter value it should change our view as well let's now look at how we can use parameters in a moving average chart when we have very busy or very volatile charts it can be helpful to add a moving average as it can smooth out the data and expose some patterns in this example i have a daily sales chart but you can see that it's very busy we can add a moving average to this chart let's copy sum of sales by pressing control dragging it over and in the second sum of sales clicking on the drop down adding a quick table calculation moving average let's make this into a dual axis chart so on the drop down of the second pill dual axes let's make sure the colors are different so i'm going to set my moving average to a different color and we are also going to synchronize the axis so right click synchronize axes we can also now hide the second header right click on check show header now this moving average by default is a three unit moving average for this chart the unit is day so we are looking at a three day moving average however if we want our end users to be able to play around with this moving average and take a look at the patterns we can add our parameter let us have a closer look at this moving average calculation so on the drop down of the pill let's edit the table calculation and in here we can see that this calculation considers the previous two values as well as the current value now if we want to make this number dynamic we need to do this in a calculated field so let's close this and let's drag over the pill that has the table calculation onto our sidebar let's rename this to moving average and let's inspect this so right click edit so what we can see is that the previous two days is hard-coded in the formula and we can replace this with a parameter value let's close this first let's create a new parameter create parameter and let's call this previous end days let's change this to an integer let's leave this as two as a default value but we can consider a range of values so perhaps a minimum of one day a maximum of a hundred days and also maybe a step size of one let's click ok and let us show this parameter remember that by default this will not do anything we need to wire this in so let us go back to our moving average calculated field right click edit and in this case instead of a -2 we are going to replace this with our parameter value so let's drag that over previous end days and let's click apply adding this parameter can also help us understand what moving averages do so in this case the more days that are considered in a moving average the smoother the pattern becomes so we can see some kind of pattern now even though the main chart is still pretty volatile moving averages can help us see some patterns more clearly and it's applicable to really volatile data sets for example sales and stocks let us now look at how we can create and use date parameters for example if you have a line chart and you want your end users to be able to select a certain date interval we can use two date parameters one for the starting date and one for the ending date so let's create the two parameters first under drop down create parameter let's call the first one from date this is going to be a date data type let's set the current value to january 1st 2018 let's also set the display format so on the drop-down i'm going to choose a full date and we are going to leave the allowable values to all so it's going to show as a calendar picker let's click ok let's duplicate this parameter and let's edit the duplicate edit and let's call this one to date and let's set this to 12 31 2019. let's click ok now let us show both of these parameters right click on from date show parameter right click on to date show parameter to test this out you can click on the parameter control and it should bring up a calendar picker now what we want to do is to use these parameter values in a reference line and to be exact we are going to use a reference band so in your sidebar in the analytics tab we are going to choose a reference band so drag this over we want to set this at the table level for the month date once we open this up we can select our parameters so on the drop down notice in here that even though the parameter is not in your canvas it is still accessible from the reference line fields and if all we want to do is to show the parameter value as reference lines we do not need to create calculated fields because they are visible from this drop-down so let's set this from from date and let's also set the to date so as we change these settings we can also see our view changing so i'm also just going to change the label so instead of computation i'm going to set this to value same thing for band 2. so instead of computation this is going to be value if we want to make adjustments in formatting we can also do that let's click on ok for now and let's see what happens when we change the dates so for example if i change this to february 1st we can see that the reference line actually moves other things that we may want to do for this particular chart is perhaps change the title so that this reflects the date range and perhaps also the total sales for this particular date range we can easily add our parameter values because remember these are global values that are accessible from anywhere in your workbook so let's double click on that title sales from let's insert from date to and let's also insert to date if we wanted to add the total sales value we are going to need to create a calculated field so let's create that so under data on the drop down create calculated field let's call this sales in date range now i will show you some common issues that happen when we try to do this we may be inclined to think that the only logic we need is an if else statement for example if order date let's expand this greater than or equal to our from date and if the order date is less than or equal to our to date then sales and then end we can put this inside a sum function that gives us the total and let's click ok now to add this field to our title we need to introduce this field in our canvas so let's drag sales and date range let's put that to detail let's double click on our title and let's add our sales in date range i'm also just going to adjust the font size so it will fit in one line now the common issue in here is you are still going to see a range of values it doesn't really give you the total of all the sales within the selected range so what happens in here is it actually really gives you sum of sales but note that this sum of sales is subdivided by the month of order date the 11 000 is the minimum point and the 96 000 is the maximum sum of sales within this particular date range so we need to remember that each one of these points each one is actually an aggregation and what we really want is an aggregation of an aggregation and we can achieve this using a table calculation so let's adjust this calculated field and we are going to use a table calculation function called total so let's right click and edit our sales in date range let's take a look at the total function first when we click on this arrow we can search for total and this tells us the total returns the total for the given expression and in this case it's going to be the sum of all the sums we can also technically achieve what we're trying to do using a windows sum so this is going to be the sum of all the sums as well so let's add total parentheses click ok notice that this change has introduced that triangle that signifies a table calculation and what this has also done is removed the range but now just gives you a grand total so again in here the moment we change our date range this total should automatically update let's now see how we can use parameters to sort stacked bar charts we use stacked bar charts when it's important for us to show the totals but at the same time also show the composition that makes up that total one of the challenges with the stacked bar chart is it's hard to compare individual segments especially those segments that are stacked for example it's hard for us to compare all of the south regions parameters can help us with stack bar charts it can allow us to select a specific region and what we can do is move that selected region to the first bar so we can at least compare those but also have an idea what the total values are so for this example we can right click on region and from here we can create a parameter based on these values so create parameter and what this does is it automatically populates the settings for this parameter by default it only copies the values so this is going to be a static value but if we want this to keep on updating every time we open our workbook we can also choose the second option so that it will update every time the workbook opens for now we're going to keep it as static let's click ok and let us show the region parameter there are two things we want to do the first one is we want the selected region to be the first color that appears and the second one is we want to be able to sort the length of the bars of that region in descending fashion to do this we have to create a calculated field that captures the values of the selected region so let's create a calculated field on the drop down create calculated field let's call this selected region sales and all we want is the sales for that region so if region is equal to whatever was selected in the parameter is equal to region parameter then sales let's end this we can also encapsulate this inside a sum function and let's click ok first let's test out the colors let's sort the caller based on this calculated field so on the drop down sort and instead of data source order we're going to set this to field and under field name it's going to be the selected region sales so this is set to ascending fashion and we will notice right away that the selected region is central central is blue and that's showing up as your first bar let's test this one more time if we select west notice that west is green and that's the first one that shows up now the next thing we need to do is to sort the actual bars right now these bars are not sorted but what we want to do is to sort them by the highest value of that segment first so we're going to do something similar we're going to set the sort of subcategory select sort and from here we are going to sort by field and this is based on our selected region sales and we can see now that this is sorting by the length of the bar let's close this and let's test this out for all of the regions central east south and west parameters can also be used to filter unrelated data sources what i have in here are two charts the first one is sales over time the second one is a sample chart that shows web traffic if for example we want to put this in a dashboard and we want to be able to select a date that affects both of these we can use parameters note that there is no connection between web traffic and sales over time they do have a common data type which is a date so we can use this date using parameters if we want to affect this view so let's go to sales over time let's just reuse the from date and the to date that we used in a previous example let's say these are the parameters we want to use in our calculated field so on the drop down create calculated field and let's call this within date range and this can simply be a boolean value or a true or false value so we can check if order date is greater than or equal to our from date and order date is less than or equal to our to date let's click ok let's put this in our filter and only leave records where it's true let's click ok we can do the exact same thing for our web traffic chart let's create a new calculated field let's call this within date range as well then date range and this time around it's going to be visit date is greater than or equal to our from date and visit date is less than or equal to our to date click ok and let's put it in our filter select true and inside our dashboard we can show the parameter control and it will affect both of these charts even though they have unrelated data sources so let's show the parameter from date on the drop down again parameters to date so if we decide to select from 2017 for example 2017 then both of these charts are going to be affected before we move on to the next use cases let's look at a construct first that you may need to use often when you're dealing with parameters one construct that you should be aware of is the case statement as you are likely to use this a lot the case statement is a logical operator that allows expressions to be evaluated and uses the value of the first match we will use this case operator in our calculated fields so we can check what the parameter value is and determine the appropriate value or logic to be applied note that when we are comparing text or strings the values you have in your calculated field must match exactly to the values you have in your parameter list even the case has to match if you accidentally type in a different case for example lowercase or uppercase or if for example you added extra spaces or extra punctuation those won't be considered matches we need exact matches for this to work it is also important to note that the case statement is equivalent to using if-else statements if you're more comfortable using if-else statements we tend to use the case statement more especially for parameter matching because it tends to be more concise and also requires less typing in some ways it's also easier to read in this example the first few lines that are highlighted they are equivalent so whether you choose case or if statement it will be a matter of preference so let's now look at a use case where we're allowing our end users to choose the dimensions that are showing up in your view we can use a parameter if we want our end users to be able to choose which dimensions are being shown on screen let's create a new parameter let's call this choose dimension let's make this a string and this time around we are going to choose a list we're going to enter in exactly the values that we want to show in this parameter drop-down list let's add customer product and state let's click ok let's also show the parameter control let's right click and show parameter now what we want to do is for this parameter to be able to dictate what is being used in your row shelf right now this is static this is always going to be a customer name so in this case we need to create a calculated field that helps us determine the correct dimension to show we're going to use our case statement in our calculated field let's create a calculated field let's call this chosen dimension so instead of an if else statement we are going to use the case statement so case let's use our parameter when customer is chosen we want the dimension to be the customer name then customer name now let's verify all the other values we have in this parameter list we also have product and state so when product is chosen then we want this to be product name when state is chosen then we want this to be the state dimension end remember we mentioned that this has to be exact whatever we type in here in these strings has to match the values we have in that parameter list let's click on ok now we are going to use this dimension in our row shelf so replace this and let's sort if we have a parameter determining our dimensions we should add additional indicators that remind our end users what they're looking at and a good place to do this will be at the title level let's double click on the title this is going to be sales by and let's insert our parameter value we can also make this a slightly different color so it's an indicator that this value is dynamic or that this value can change now we can hide the field labels so we can right click on this chosen dimension right click hide field labels and now let's test this out this is my customer by product and by state we can do something similar if what we're trying to swap in and out are measures and aggregations for example if we want to show total sales sometimes total profit sometimes maybe average sales and average profit we can use parameters for that let's create a new parameter let's call this choose measure i will use a string data type for this parameter because i want to be able to use this as a label later on so on the drop down string and under list total sales average sales total profit average profit and click ok let's show the parameter and similar to the dynamic dimension we're going to create a calculated field that helps us determine the correct measure to show so on the drop down create calculated field let's call this chosen measure we're going to use case statement again case let's drag our parameter over when total sales is selected then we want the sum of sales when total profit then we want the sum of profit when average sales then avg sales when average profit then avg profit and end let's click on ok let's change the default format of this new measure so right click default properties number format make this currency custom zero decimal places and once we are ready we can swap out this chosen measure to what we have in our row shelf right now drag this over let's test this out first average sales total profit average profit let's add some indicators so it's very clear what the chart shows and what the chart represents let's change our title let's add our parameter name this is choose measure let's call this overtime adjust the formatting a little bit click ok so again test this out total sales average sales we have total profit also average profit one reason i have chosen a string for the parameter data type is because i want to be able to use this as a label that simulates an axis so let's drag choose measure over this will give us whatever the chosen measure is we are going to remove the axis title as well as the field label let's right click on the axis edit axes let's remove this title let's rotate our header and remove our field labels so right click hide field labels one last check total sales this should now be shown both on the title and what simulates our axes average sales total profit average profit one more use case that introduces interactivity is allowing our end users to choose which charts to show this is also sometimes called dynamic sheet swapping this is a well-documented technique that utilizes layout containers and filters and the actual sheet swapping needs to happen at the dashboard level i have three charts in here that i want to swap a bar chart a line chart and a map and the technique in here is to make sure you have a layout container either a horizontal or a vertical make sure the charts you want to show are all in the same container and the reason for that is all of the contents in a container will take up a hundred percent of that space so when you have multiple charts for example in the same container let's say we have three of them in here and if a couple of these charts disappear whatever is left will occupy the rest of the space let us start by creating a parameter that has our chart choices so on the drop down create parameter let's call this choose chart this is going to be a string and our choices are going to be in a list click on list let's select all bar line and map click ok and let us show this parameter now what we want to do is to add something to filters that will evaluate to true if the selection is either all or bar the caveat here though is the filter shelf will not accept your parameter therefore we need to create a calculated field so let's create a calculated field let's call this chosen chart and the only value we need inside this calculated field is the parameter value so let's drag that over and click ok let's put this in the filter shelf and in here we are going to evaluate the values based on a custom value list so we will create our own list that will allow our calculated field to be evaluated to true and in this case for our bar chart the values that should be true will be all let's click on the plus sign and bar so what we are saying is if the choice is all then it matches a value if the choice is bar it also matches a value so it should evaluate the true and retain the chart however if the value is neither of these the chart should disappear so let's try this out let's click ok right now the choice is all therefore we are seeing the chart if we select bar we should still see the chart if we select line the chart should disappear if we select map the chart should also disappear we need to do the exact same steps for the remainder of the charts that we have so i'm just going to do that quickly i'm going to set the parameter value to all first and let's set up all of our charts in our dashboard so in our dashboard we're going to add a vertical container and we are going to put the three charts here let's put the bar let's set the parameter to floating for now let's add the other two charts let's add the line make sure they're in the same container and let's also add the map and now let's take a look at what happens when we change our parameter choice right now this is all but if we decide that we only want a bar the bar chart remains but the line and the map they disappear if we select line the other two charts disappear if we select a map the map is retained but the line and the bar chart they disappear so right now all we need to do is clean up the formatting in this case we are going to hide the title so that the chart swapping is a little bit more seamless let's try it again all bar line and map let's review how parameters and filters are different i do have a full video explaining filters if you would like a refresher i will link it up in the card above in description down below a parameter is independent of the data source while a filter is dependent on a data source we can also see this manifest itself when we add quick filters for example if i add a quick filter for sum of sales show the filter see how the filter has exact numbers in the boundaries it is because this is derived from the underlying data with our parameters we can set our own values and our own boundaries a parameter scope is at the workbook level it can be seen by any worksheet within the same workbook however filters they're applicable by default at the worksheet level we can however apply our filters to different worksheets if we want to the purpose of a filter is to narrow down data however a parameter is not limited to just narrowing down data maybe it's something that we can use in calculated fields or reference lines or filters that's another thing we should note parameters can be used in calculated fields whereas our filters we cannot embed them inside expressions in terms of form filters can have multi-select values parameters at this point are single select or open form or based on a list actions are available for parameters but not available for filters which leads us to the final topic there are parameter actions this enables parameter changes to be done through interaction with your view either by using hover select or menu let's take a look at the final use case for this example we are going to add some dynamic reference lines to add some dynamic reference lines let's start by creating two parameters one for a sales threshold and another one for a profit threshold so on the drop down create parameter let's start with our sales threshold sales threshold let's set this to be an integer let's set the display format to currency zero decimal places let's click ok and let's show this parameter let's add a second parameter so on the drop down create parameter this time around this is going to be the profit threshold profit threshold let's set this to integer as well display format currency zero decimal places and click ok let us display this parameter as well let us now add two reference lines that use the threshold values so in your sidebar in the analytics tab let's drag over reference line let us start with sum of sales this should use the sales threshold value so on the drop-down sales threshold in terms of label let's set this to custom let's type in sales and add the value so in this arrow select value let's set the formatting so that this is a dashed line we're also going to fill below so just a light gray shading click ok let's do the same thing for our profit threshold drag a reference line this time around we're still targeting the table scope but we are only looking at sum of profit we're going to use our profit threshold under label it's going to be custom let's call this profit and still display the value set the line to be dashed and we are also going to fill below click ok one more formatting change we're just going to move the labels to the right and the label to the top so let's right click format on the reference line label we're going to change our alignment so horizontal alignment to the right vertical alignment to the top let's do the same thing for profit right click format alignment is to the right and to the top let's just test this out first if we change the value of our sales threshold and our profit threshold manually we should expect these reference lines to change so for example sales threshold of a thousand and profit threshold of a thousand so we can see that they're changing now what we want to do is for these parameter values to dynamically change when we hover over any of these circles we want the corresponding sales value to change our sales threshold and our profit value of that selected circle should also change the profit threshold and to do that we need to add our parameter actions we need to add two so under worksheet actions we're going to add the first one for sales add action change parameter this one is for sales we're going to set this action to run on hover we're targeting our sales threshold and we are going to use the sum of sales value sum of sales click ok let's add one more action for profit add action change parameter this time around this is for profit it's going to run and hover as well we are going to target our profit threshold and we are going to use the total profit or the sum of profit click ok let's give this a try when we hover over any of these circles the sales threshold and profit threshold values should change and in here we can see that this is fairly responsive every time we hover over the reference lines are actually changing we have covered a lot in this video we talked about parameters what they are how we can create them we also demoed 10 different use cases that use parameters and we've covered tips and tricks as well as common constructs like case and if else statements we've also highlighted the differences between parameters and filters and also did a quick introduction to parameter actions i hope you found this video useful i hope you learned something new i hope this has helped you understand parameters a little bit better thank you so much for watching i appreciate your time and i'll see you again next time