1 Reply Latest reply on Dec 22, 2016 3:32 AM by Yuriy Fal

    Filter data source based on multi-valued parameter

    Brian Derstine

      On the surface, this would seem to be a fairly easy thing to do, however, Tableau does not appear to support this.


      Basically, I want to be able to do something like the following query:


      SELECT * FROM PrimaryTable

      WHERE PrimaryTable.ID IN (SELECT DISTINCT PrimaryTable.ID from SecondaryTable where SecondaryTable.groupname IN ('Group1', 'Group2', 'Group3'))


      but the closest I can get using Tableau 10 is:


      SELECT * FROM PrimaryTable

      WHERE PrimaryTable.ID = (SELECT DISTINCT PrimaryTable.ID from SecondaryTable where SecondaryTable.groupname  = <Parameters.Select Group Name>)


      The same as above, but in paragraph form:

      I am connecting to a relational database (PostgreSQL) with data in multiple tables. PrimaryTable has one row per ID and the relevant fields include ID, measure1, measure2, etc.   Each person belongs to one or more groups and this relationship is stored in SecondaryTable with multiple rows per ID and the relevant fields include ID, groupID, groupname, etc.  With the result, I want to make scatter plots of measure1 vs. measure2 for each ID, but only include IDs for people who are in selected groupnames.  (i.e., filter the PersonIDs in PrimaryTable using a multi-select filter on the groupname in SecondaryTable)


      Things I have tried:

      1. Joining the two tables together.  This is easy to achieve, however, it has a number of problematic side-effects: the resulting dataset is massively bloated and slow due to having several duplicate rows per ID.  When the data is plotted, I see hundreds more marks per plot than I actually have and computations are incorrect.  Turning on "Aggregate Measures" removes all the individual data points which is not helpful. See: http://onlinehelp.tableau.com/current/pro/desktop/en-us/help.htm#joining_tables.html#troubleshoot


      2. Blend the two tables as separate data sources.  Again, this is easy to achieve because the two tables can be blended on ID, however, the resulting data table has aggregated all of the individual ID data away.  Not good.  I want to look at plots where each of the points represents an individual ID.


      3. Use a Custom SQL query, and filter the results using a Parameter for groupname.  This is also easy to achieve and it reduces the bloat, is faster, and avoids over-counting, however, I can only select one value for the parameter and I need to be able to select multiple values for the parameter.  This is the closest thing I've found to what I want to achieve.