Search code examples
tableau-apitableau-desktop

How to use table data as parameter for Custom SQL in Tableau


I have 2 tables in a SQL Data Source in Tableau, tab1 and tab2. I want to write a custom SQL using tab1 and use the data from tab2 as input parameter. tab2 has version column whose values i want to use as parameter for below query on tab1.

Custom SQL:

select col1, col2, version from tab1 where version <= <Some Parameter>

There would be a filter that will have all the versions from tab2 and when i select a version, it should be used as input parameter for custom sql of tab1.

I am new to Tableau, not sure if this is possible.

I looked into if it is possible to create a filter using another table data, but looks like that is not supported option.


Solution

  • Create two separate data connections. One being your custom sql and the other just a table connection on tab2. Parameters can be used across data sources. Create a parameter on the tab2 data from the column desired. Now use this parameter in your custom sql query. For more information on that, scroll down to "Use parameters in a custom SQL query" section of https://help.tableau.com/current/pro/desktop/en-us/customsql.htm