1 Reply Latest reply on Dec 24, 2018 9:50 AM by Ken Flerlage

    Data Source filter when it is applied

    Błażej Luberadzki

      Hello,

       

      I am wondering when data source filter is applied on live connection - is it pass through in sql code to database or it is done by Tableau engine after retrieving data from database. On below example after converting data source to custom sql I do not see "where" clause which should exist as I am using data source filter:

       

       

      Data source filter:

       

       

      Convert to sql do not show this filter

       

        • 1. Re: Data Source filter when it is applied
          Ken Flerlage

          I just tested this with my local SQL Server database and found that it did, in fact, pass the data source filter to the SQL. For example, I have this setup:

          Then I added this filter:

          I ran a SQL Server trace and found that it executed the following SQL:

           

          SELECT TOP 1000 [tblSales].[Customer] AS [Customer],

            [tblSales].[Item] AS [Item],

            1 AS [Number of Records],

            [tblSales].[Sales] AS [Sales],

            [tblSales].[Transaction] AS [Transaction]

          FROM [dbo].[tblSales] [tblSales]

          WHERE (([tblSales].[Transaction] >= 1000) AND ([tblSales].[Transaction] <= 1010))'

           

          If you then convert that to custom SQL, you are correct that it does not add the data source filter. In my case, for example, it shows:

           

          SELECT [tblSales].[Transaction] AS [Transaction],

            [tblSales].[Customer] AS [Customer],

            [tblSales].[Item] AS [Item],

            [tblSales].[Sales] AS [Sales]

          FROM [dbo].[tblSales] [tblSales]

           

          However, when executed, it does add the data source filter to the SQL, though in a rather strange way:

           

          SELECT TOP 1000 [Custom SQL Query].[Customer] AS [Customer],

            [Custom SQL Query].[Item] AS [Item],

            1 AS [Number of Records],

            [Custom SQL Query].[Sales] AS [Sales],

            [Custom SQL Query].[Transaction] AS [Transaction]

          FROM (

            SELECT [tblSales].[Transaction] AS [Transaction],

              [tblSales].[Customer] AS [Customer],

              [tblSales].[Item] AS [Item],

              [tblSales].[Sales] AS [Sales]

            FROM [dbo].[tblSales] [tblSales]

          ) [Custom SQL Query]

          WHERE (([Custom SQL Query].[Transaction] >= 1000) AND ([Custom SQL Query].[Transaction] <= 1010))'

           

          Hope this helps! If it does, please be so kind as to mark this as the "correct response" so we can close this thread and others can quickly find the answer. Thanks!