Beruflich Dokumente
Kultur Dokumente
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
DrawingwithNumbers
Thoughts on data visualization and Tableau
Currently (July 2013), the #1 most-voted-for Idea for Tableau is Dynamic Parameters. Here, Ill show
you a technique for using Tableau data blending to create a dynamic, data-driven
parameter.Were going to use a loosely coupled secondary data source to get the information
associated with the parameter and return that information to the primary data source, where it can be
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
1/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Choose one value to build a comparison to other values, such as nding the distance from a
chosen origin city to a set of destination cities, or a market basket-type analysis where we
want to compare one against others.
Set the limits and input data to an algorithm that is then used to create other results, for
example to get a starting set of data to use to build a projection, such as an executive
retirement forecast model.
Read on for a description of the technique and demos of all three options!
to stop the Fields cannot be used from the [secondary] data source error:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
2/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
in the secondary as you need, which is probably all of them except for the Blend Field.
7. Finish setting up the view.
8. If you have multiple worksheets for a dashboard, you can set up scoped or global lters.
Demonstration #1: Choosing a Customer and Showing Pro t & Sales for
Customers within X% Sales of Selected Customer
This is a totally made-up scenario using Superstore Sales to do a market basket analysis. Here, were
picking a particular customer, nding out their sales, then showing every other customer that has sales
within X% of the selected customer. Heres the view:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
3/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
SalesRange
ExecRetirementForecastModel
DistancefromSelected
SalesRangeWorkout
ExecRetirementForecastWorkout
DistancefromSelectedWorkout
There are a few other ways we could go about this, such as:
Using a parameter to identify the customer. This would have to be updated every time
theres a change in the list of customers.
Putting the basket creation logic into Custom SQL or custom queries. This depends on skills that
not all Tableau users have.
Data blend and table calculations. This is powerful, but complicated and potentially the
slowest option. Also depends on skills that not all Tableau users have.
This is how I set this up the data blend for a dynamic parameter:
1. For this example, I used Superstore Sales and simply duplicated the data source to make the
secondary source of Customer Names. In practice, Id probably use a separate data source that
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
4/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
just had the names and sales to reduce the size of the secondary source (in other words, use the
minimum number of dimensions and measures).
2. In Superstore Sales, I built the following calculations in the primary data source:
Sales for Selected This is the sum of sales from the secondary
Sales Range Filter Used to lter the customer list based on the % dierence, using a
Sales Range from Selected Customer parameter.
IF(ABS(SUM([Sales])[SalesforSelected])/[SalesforSelected])<=[SalesRangefromSele
1
END
Selected Customer Identies the Selected Customer from the secondary so we can use
that on the Color, Shape, and Size Shelf:
IFMIN([CustomerName])==MIN([dupSampleSuperstoreEnglish(Extract)].[CustomerName]
"SelectedCustomer"
ELSE
"Other"
END
Size 1 Has the formula SIZE()-1 and a Compute Using of Customer, it is used for the title.
3. In both Superstore Sales and the duplicate Superstore Sales, created a Blend Field dimension with
a value of 1.
4. Now to build the initial view:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
5/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
5. Now to add the quick lter on the Customer Name from the secondary source. Once I choose one
customer, theres now only one mark in the view:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
6/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
This is because Customer Name exists in both data sources and Tableau is automatically linking
the two dimensions. So
6. In the secondary data source, turn on the relationship for the Blend Field, and turn o
the
You will now see all the marks again, as in the view from step 3 above.
7. To nish up this view, I put the Selected Customer eld on the Color Shape, and Size Shelves, put
the Sales for Selected Customer on the Level of Detail Shelf, put the Sales Range Filter on the
Filters Shelf ltering for non-Null values, edited the title and added a couple of reference lines:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
7/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
And there you have it, a completely dynamic view with no SQL necessary, and the only table calculation
is to give us some extra information in the worksheet title.
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
8/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
SalesRange
ExecRetirementForecastModel
DistancefromSelected
SalesRangeWorkout
ExecRetirementForecastWorkout
DistancefromSelectedWorkout
1. Setting up the data. This example is a bit more complicated because of the data arrangement and
the goals. In the main data, there is a row for each executive:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
9/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
To build the forecast, were using table calculations. Since table calculations require something to
address over, we need a set of dates.Unlike set of dates need to be the primary data source. The
reason why is that if we make the executive data the primary, it doesnt have enough level of detail to
show the individual dates from the secondary, and we see a bunch of asterisks:
An alternative solution that would get rid of the asteriskswould be to do a Cartesian aka cross
product query of a set of dates for every executive. In that case, wed have everything needed
to do the view and could use a regular lter on the executive. However, Custom SQL isnt
everyones cup of tea, so we have this data blend solution as an alternative.
Therefore, we make the dates primary, and executive data secondary, then use the dimension
lter on the secondary to pull the information for a particular executive. This ability to lter a
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
10/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
dimension in the secondary without needing a linking dimension in the primary is one of the most
useful new additions to data blending in v8. For the date data, I used Joe Makos 2 row data source
scaold technique. You can see his Think Data Thursday presentationon data scaoldingfor complete
details, the short form is that we take a data source with two values, then assign dates to them (which
can be dynamically calculated), then turn on domain padding in Tableau via the Show Missing Values
option to ll in the dates in-between. So this:
is brought into Tableau, then with a [Years to Retirement] parameter and this calculated eld for
the Date:
CASE[Value]
WHEN1THENTODAY()
WHEN2THENDATEADD('year',[YearstoRetirement],TODAY())
END
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
11/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Tableaus domain padding occurs before the blended data is added, so we can use this padded source
(no SQL required!) to blend in the executive data. For more details, see my earlier post onBlending
Secondary Data into Primary without Linking Data in Primary.So thats step 1 of the process.Heres the
rest:
2. In the primary data source, I built out a set of parameters and calculated elds for the data. For
example, the 401(k) Balance calc has the following formula, where the 401(k) Growth Rate and
Annual Contribution are both parameters. The table calculations all have a Compute Using of the
Date.
IFFIRST()==0THEN
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
12/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
SUM([ExecutiveData(executivedata.xlsx)].[Starting401(k)Balance])
ELSE
PREVIOUS_VALUE(0)*(1+[401(k)GrowthRate])+[Annual401(k)Contribution]
END
3. In both the primary and secondary, build the Blend Field with a value of 1.
4. The initial view is just the padded out date. I work with this way for table calculations to get the
addressing and partitioning right, then will duplicate the sheet later to create the nal view.
5. Add the lter on the Executive Name from the secondary.
6. Turn on Blend Field as a linking dimension.
7. Add the table calculations, set their Compute Usings and validate, add the parameter
controls, build the title, etc. Once that was working, then I duplicated the worksheet and used
those settings to build the nal view:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
13/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
pick an origin city and return the distance (and potentially other data about) destination cities.
There are a couple of other ways to go about this:
Build a data source that has a row for every origin/destination pair with latitudes and
longitudes for both, and potentially also pre-computed distances. This is the ultimately the
most exible in terms of what can be done in Tableau, and requires the most eort and
resources to set up.
Use a parameter to select the city, then a table calculation to propagate the
latitude/longitude for the selected city to all the other cities, then further table calculations to
compute the distance. This was what I rst tried out, and Jim Wahl completed in the thread.
The parameter would have to be updated any time new origins are added.
Heres the alternative:Use a secondary data source to select the origin city, then feed back the
latitude/longitude of that for use in a dynamic distance calculation. With the computations
happening as regular aggregates instead of table calculations, we can then take advantage of
global & scoped lters, and get some nice dynamic ltering, and will automatically update when
new origin cities are added. This should be faster than the parameter-based solution, and has a
smaller data storage footprint than the fully computed data source. Heres the view:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
14/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
SalesRange
ExecRetirementForecastModel
DistancefromSelected
SalesRangeWorkout
ExecRetirementForecastWorkout
DistancefromSelectedWorkout
longitude of all the cities. Because were needing to compute a distance between the origin
city and other cities, we cant use Tableaus built-in generated latitude and longitude.
Heres a nice little hack for using Tableau to get your latitude/longitude data: Build a map with
the points you want, then use Worksheet->Copy->Data, then Ctrl+V to paste the data back into
Tableau. Voila, instant geocoding!
2. Then I created elds in the Superstore Sales primary to bring in the origin and destination
latitude and longitude, and used a Great Circle Distance formula from the Tableau
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
15/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Knowledgebase to make a Distance calculated eld.And I created an Origin City Flag in the
primary to identify the selected city for color & shape:
IFMIN([State+City])==MIN([OriginGeoData].[State+City])THEN
"Origin"
ELSE
"Destination"
END
And heres a State+City calc for the Origin data source to use for the lter:
[State]+""+[City]
3. The next step is to create Blend Field with a value of 1 in both the primary and secondary
sources.
4. Now to build the initial view. From the primary, drag the City to the Level of Detail and
Tableau will automatically include the State & Country and start a map:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
16/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
5. Now to add the lter from the secondary. Switch to the secondary data source, drag the
State+City dimension onto the Filters Shelf and pick a city from the Filters dialog. The view will
change to only the selected city:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
17/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
6. Next, turn on the relationship for the Blend Field, and turn o
7. To build the rest of the view, I put Distance on the Filters Shelf and used an At Most lter so the
users couldnt lter out 0 distance and hide the origin city, then set it up to be a Quick Filter. Origin
City went on Shape and Size, and Distance on Color:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
18/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
To get the origin city to be red and the rest blue, I tried several dierent techniques such as
multiple discretes on colors, dierent levels of detail, and dual axes, and all of them had their
issues. Then I gured out I could use a diverging red/blue color palette. Because only the selected
origin city has a distance of 0, I set the center of palette to 1, so the origin would be red and the
rest of the marks shades of blue:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
19/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Then to demonstrate how we can use the the lter across worksheets, I set up another worksheet
to be the title:
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
20/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
21/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
building a scaold data source to use as the primary that has enough detail to enable the ltering and
computation to occur in the scaold source.
Conclusion
This can be a useful technique when scaolding is not an option and a dynamic solution is needed for
doing a comparison to other like with the map and similar customer views, or performing an
algorithmic computation across a set of rows of data as in the executive retirement calculator.Thanks
to Richard Leeke, Shawn Wallwork, and Joe Mako for their help at dierent times in putting this post
together, and go forth and blend!
Share this:
Like this:
Like
Bethefirsttolikethis.
Related
This entry was posted in Tableau v8 - The Kraken, Tips and Techniques and tagged blending, data
blending, ltering, lters, forecasting, maps, parameters on August 2, 2013
[http://drawingwithnumbers.artisart.org/creating-a-dynamic-parameter-with-a-tableau-data-blend/] by
Jonathan Drummey.
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
22/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Shawn Wallwork
August 6, 2013 at 2:42 pm
This look cool and promising Jonathan! Itll take awhile to digest. I was wondering why youd gone forum
silent, now I know. This was a lot of work. Thanks,
Shawn
Jonathan Drummey
Post author
Thanks! Ive mostly been quiet with working on my TCC presentation and summer play.
Very helpful and already put to use Jonathan! Thank you for all the hard work.
Jonathan Drummey
Post author
Eric Chesebro
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
23/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Jonathan,
Thank you very much for this very in-depth and thorough representation of dynamic parameters. I was
able to use your example to get exactly what I was looking for using version 8 of Tableau Public.
Question is Demo #3 able to be reproduced in version 6 or 7? I seem to be having issues with the
data source linkings in 6 and 7 and am unable to reproduce in these versions.
Thank you in advance.
Eric
Jonathan Drummey
Post author
Hi Eric,
All three of the demos depend on the new feature in Tableau v8 where we can use a dimension lter on
a secondary data source, so they wont work in version 6 or 7. In version 7 and earlier, what Tableau
showed as a dimension pill from the secondary on the Filters Shelf was really an ATTR() aggregate, so it
would return * where there wasnt sucient level of detail. The workarounds for v6 and v7 are to
increase the level of detail in the primary (and potentially vastly multiply your data), or to use static
parameters.
Jonathan
Pingback: User Dened Functions and Process Control Charts | Drawing with Numbers
Nick Silhacek
June 12, 2014 at 11:32 am
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
24/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
You mentioned that in practice, Id probably use a separate data source that just had the names to
reduce the size of the secondary source.
My question is, how does the calculated eld Sales for Selected work, then? I was able to get
everything but that to work using your suggested practice.
Jonathan Drummey
Post author
Oops! Great catch, thanks! I think that might have been leftover from an earlier draft, Ive updated the
text to say use the customer name *and* sales, to have the minimum number of dimensions. There is
an alternative using a secondary source with just the customer name and then a table calc to get the
sales from the primary for the chosen customer, however that can run into issues with ltering (which is
part of why I came up with this particular solution).
Jonathan
Kelly
June 19, 2014 at 1:11 am
Hi Jonathan You cant imagine how many times Ive hit this page and downloaded this workbook. It is
so helpful in so many situations. Just wanted to say thanks!
Jonathan Drummey
Post author
Youre welcome! And to return an appreciation, Im in the middle of designing a dashboard right now
and Im regularly thinking, What would Kelly do?
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
25/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Sumesh
September 12, 2014 at 8:37 am
Hi Jonathan,
Appreciate the information you presented. I followed the rst one exactly like you presented (x% from
selected customer), but Tableau does not allow me to create a quick lter on the secondary duplicated
datasource by customer name. Am I missing something? Thanks.
Sumesh
September 12, 2014 at 9:17 am
Jonathan,
It actually worked after a few iterations of trial and error. I had to drop the customer name in the lter
and from there I was able to create a quick lter. The only issue I am now seeing is that the quick lter
has a null option in it and I have not been successful in removing it. Thanks.
Jonathan Drummey
Post author
Unfortunately, Tableau always puts in a Null option on lters using dimensions from secondary sources.
This is a just in case option for the situation where the primary source doesnt have corresponding
values in the secondary, Tableau doesnt go the extra step to determine whether the primary and
secondary have complete domains. Heres the link to voting for this to change:
http://community.tableausoftware.com/ideas/2847
Alex
February 16, 2015 at 12:26 pm
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
26/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Jonathan Thanks, this is a great post a year or two old and still going strong!
Question: I have tried to replicate your example with my data (which is using campaigns instead of
customers). I followed the steps exactly as you wrote and have studied your workbook, but for some
reason my viz is not displaying the other marks (in your example, the 143 other customers). It seems
that since my secondary lter (Campaign Name) is on the Filters shelf, it is limiting the view to that
specic campaign, which obviously defeats the purpose since Im trying to show how this particular
campaign stacks up against all other campaigns. This leads me to believe that my join might be
incorrect, but I have double-checked it and found no dierence between your workbook and mine. Any
thoughts on where I might be going astray?
Best,
Alex
Alex
February 16, 2015 at 12:31 pm
and of course I gure it out as soon as I posted that (feel free to remove it). I was still linking on the
Campaign eld in addition to the Blend eld. As soon as I removed the link to Campaign Namevoila!
Thanks again for a great workaround to dynamic parameters.
Alex
Jonathan Drummey
Post author
Hi Alex,
Im glad you gured it out! Im leaving the comment up because I think itll be useful to others, making
sure the linking dimensions are exactly what you want (no more, and no less) is key to getting the data
blend to return the desired values.
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
27/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Bobby Weaver
February 16, 2015 at 4:17 pm
Jonathan,
Since the Null option in the Quick Filter cannot be removed entirely or just moved to the bottom of the
value list, is it possible to make the Quick Filter default to a non-Null value?
I know the setting of a default value could be achieved in Tableau Server with the Remember My
Changes feature but I was looking for a solution that could be applied prior to publishing.
Thanks,
Jonathan
February 16, 2015 at 6:24 pm
If you have selected a lter option prior to publishing, itll stay in place when published.
Jonathan Drummey
Post author
Hi Bobby,
When we publish a workbook to Server each worksheet & dashboard each Quick lter for a discrete
retains the values that were set when published, so thats the default. I dont know of another way to
choose a specic value as the default.
Chandra
August 18, 2015 at 12:21 am
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
28/29
4/14/2016
CreatingaDynamicParameterwithaTableauDataBlend|DrawingwithNumbers
Hi Jonathan
What if I were to nd out the Penetration of a Particular Item
i.e. Countd of Order Id (for an Item or a set of Filters) / Countd of Order Id (Across a Category No
Filters Applied)
How can I do this ?
Chandra
Jonathan Drummey
Post author
Hi Chandra,
There are a few ways to do this, see http://www.theinformationlab.co.uk/2013/01/14/maintainingpercent-of-total-whilst-ltering/ for a roundup (including my comment at the end).
Jonathan
Pingback: Alteryx Newbie Creates Dynamic Parameters in Tableau First Day by Jonathan Drummey |
DataBlick
http://drawingwithnumbers.artisart.org/creatingadynamicparameterwithatableaudatablend/
29/29