Parameters allow for a lot of awesome Tableau functionality. When working with template publishing, it makes sense that you might want to do variations on the display names for a parameter, or even set the options arbitrarily for each site you will publish to. However, despite looking like part of a data source, Parameters are actually stored as their own data source within a workbook. This means we’ll need to consider how to insert and modify them in each workbook.
Note on terminology: I’m trying my best to refer to Tableau Parameters with an uppercase P to distinguish from all the other possible parameter things out there.
Each workbook with Parameters has a datasource tag with ‘Parameters’ as its name property. Here’s an example:
<datasource hasconnection='false' inline='true' name='Parameters' version='10.0'> <aliases enabled='yes' /> <column alias='Spring 2008' caption='Integer List' datatype='integer' name='[Parameter 1]' param-domain-type='list' role='measure' type='quantitative' value='20080101'> <calculation class='tableau' formula='20080101' /> <aliases> <alias key='20080101' value='Spring 2008' /> <alias key='20090101' value='Spring 2009' /> </aliases> <members> <member alias='Spring 2008' value='20080101' /> <member alias='Spring 2009' value='20090101' /> </members> </column> <column alias='Glarg' caption='String List' datatype='string' name='[Parameter 2]' param-domain-type='list' role='measure' type='nominal' value='"bleh"'> <calculation class='tableau' formula='"bleh"' /> <aliases> <alias key='"bleh"' value='Glarg' /> </aliases> <members> <member alias='Glarg' value='"bleh"' /> <member value='"hurmph"' /> </members> </column> <column caption='Any String' datatype='string' name='[Parameter 3]' param-domain-type='any' role='measure' type='nominal' value='"Something"'> <calculation class='tableau' formula='"Something"' /> </column> </datasource>
What can we take away from this initial snippet?
- Each Parameter is actually represented as a column with an internal name attribute that never changes. The pattern is [Parameter N], so if we want to add to them, the next name will be [Parameter N+1].
- The actual value is stored both in the column tag itself using the value attribute and as a calculation tag inside the column tag. The formula attribute stores the real value (that is, the Value portion rather than the alias declared in ‘Display As’)
- When a List of options is set, there is both an aliases tag and a members tag which cross reference each other. There is only an alias tag if a ‘Display As’ value exists for an option; whereas there is always a member tag for everything in the list
- String values are recorded with an entity encoded quote around the values; this follows the pattern seen elsewhere in the TWB and TDS XML.
For the numeric and date types, you can also set a range. This is expressed as a range tag inside the column:
<range granularity='2' max='232' min='1' />
For Date and Datetime fields, you also set what period you want the steps to be in:
<range granularity='1' max='#2016-01-01#' min='#2015-01-01#' period-type='month' />