6 Replies Latest reply on Jan 12, 2017 1:35 AM by Wim Kegels

    Dynamically selecting table

    sai.prasad

      Hello all

       

      I have a scenario were I have two users whose Data comes from different tables. When published in tableau server , user1 should'nt be able to see user2 data. I have done this using sites option in Tableau server, where I was using two Dashboards for two tables. But I was told that dashboard should be one and I should implement both tables in same dashboard. Then I used Row level security to do it where I have used one table with both users data. I could do it successfully. But eventually I have to used two tables. How can I do this using two tables where tables should be selected dynamically based on the user.

       

      Thank you.

        • 1. Re: Dynamically selecting table
          Wim Kegels

          Hi Sai,

           

          Have you tried filtering on data source?

          From Create a User Filter and Secure it for Publishing : "Rather than maintain user filters and special permissions on each published workbook, you can filter a data source, and then publish the data source to make it available as a shared, one-to-many resource for anyone who uses that data."

           

          First, create a calculated field that selects the correct user ( USERNAME() = "username" or something like that).

          Then, add this calculated field to the data source filters.  In the upper right corner of the data source page, click Add:

          Add the calculated field you created as dynamic filter.

           

          Hope this helps!

           

          Kind regards,

          Wim

          • 2. Re: Dynamically selecting table
            sai.prasad

            Hi Wim

             

            Thanks for the quick response. I have already used Row level security and used the calculated field [Username] = Username()

            I could successfully implement it. Were I had two users  "User1" and "User2" in data and two same two users in Tableau server . So that when "User1" logs in he can only see his relevant data and ViceVersa. But I am supposed to used two TABLES "Table1" and "Table2" for User1 and User2. Is there a way to write Customer sql query to select table based on User.

             

            Thank you.

            • 4. Re: Dynamically selecting table
              Wim Kegels

              Hi Sai,

               

              This should be possible.  You can use parameters you've created in the workbook in custom SQL statements using the "insert parameter" option on the bottom of your custom SQL box.

              haven't tested it, but you could use something like

               

              IF <parameter.user> IS "name1"
                SELECT *
                FROM Table3

              ELSEIF <Parameters.user> IS "name2"

                SELECT *
                FROM Table2

               

              For more information visit Connect to a Custom SQL Query 

               

              Good luck!

               

              Kind regards,

              Wim

              • 5. Re: Dynamically selecting table
                sai.prasad

                Hello Wim

                 

                Thanks for the help, I have tried to implement the above query you mentioned. But I am getting an error. I have created a Parameter on User name. which contains user names as Test1 and Test2. Its a string parameter. I have inserted the same in the query but it gives an error. May be the syntax I have written must be wrong. Here is the screenshot.

                 

                Thank youScreenshot 3.png

                • 6. Re: Dynamically selecting table
                  Wim Kegels

                  Hi Sai,

                   

                  I'm no expert on SQL, perhaps the IF statement is not supported.

                  You could try a CASE statement?

                  SELECT

                       CASE

                            WHEN <parameter> is "test1"

                                 THEN Table1

                            WHEN <parameter> is "test2"

                                 THEN table2

                       END

                   

                  or something like that?

                   

                  Perhaps custom queries aren't supported by your ODBC connection...

                   

                  Kind regards,

                  Wim