Tag: Read Tableau Views from a Database

  • Writing and Reading Tableau Views to and from Databases and Text Files – Part 2

    How to use R, a Tableau connection to R and Calculated Fields to store and load the underlying data of a defined Tableau View in a Database or Text File (part 2 of 2)

    R - Photographer: Karyn Christner (flickr.com)This is the second part of Michael Martin’s guest post on how to use Tableau and R to read and write the underlying data of a Tableau view from / to an ODBC database.

    Michael is the Managing Partner at Business Information Arts, Inc, Tableau Partner, Tableau Certified Consultant, Tableau Instructor and leader of the Toronto Tableau User Group.  Last, but not least, Michael is the only person I know who is using Tableau Software since version 1.0.  

    NOTE: You may need to zoom into some of the screen shots below for legibility reasons. Also, the text below contains references to the “Level of Detail Shelf“.  This is synonymous with the Detail Pill in the Tableau Marks Card within the Tableau 9.x and 10.x user interface.  As mentioned in the introduction to part one of this post, including a ‘$’ character as part of an RODBC object name (for example crs$odbc, crs$odbc.tablescrs$dataset) could cause an error on your system, and the affected calculation will fail.  If this happens, replace instances of $ within an RODBC object name with another character within the affected calculation, such as an underscore – i.e. _.

    Supporting files and a README file are available for download at the end of this part of the post. Please look at the README file first.

    The author would like to thank Leonid Koyfman for his suggestions.

    The first part of this post walked you through the process of

    • downloading and installing R and RStudio
    • installing the required R packages,
    • setting up the ODBC database connection
    • writing the Calculated Fields in Tableau to read the underlying data of a Tableau view from a database

    In the first part, we have only run SELECT queries, but we could also run INSERT, DELETE, UPDATE or INSERT INTO (Append data) queries – all we need to be is pass a valid SQL statement to a Calculated Field that establishes an ODBC connection to the Database and run the SQL statement.

    Today’s second part of the post will

    • show how to insert data of a Tableau view into a database
    • demonstrate the necessity of aligning the orientation of the view and the Table Calculation
    • show how to perform data definition queries
    • provide the general caveats of the technique
    • demonstrate an analysis technique that leverages multiple exports of a Tableau View based on the Superstore Dataset to SQL Server
    • give some insights on performance and upper limits
    • provide some useful links regarding the integration of Tableau and R

    (more…)

  • Writing and Reading Tableau Views to and from Databases and Text Files – Part 1

    How to use R, a Tableau connection to R and Calculated Fields to store and load the underlying data of a defined Tableau View in a Database or Text File (part 1 of 2)

    R - Photographer: Karyn Christner (flickr.com)My good friend Michael Martin is kind enough to contribute another guest post to Clearly and Simply.

    Michael is the Managing Partner at Business Information Arts, Inc, Tableau Partner, Tableau Certified Consultant, Tableau Instructor, leader of the Toronto Tableau User Group and – as Interworks calls him for very good reason – a Tableau Maestro.

    In his article, Michael will show us how to store the underlying data of Tableau Views in a database or a text file using R and Tableau Calculated Fields. Michael's post will come in 2 installments.

    NOTE: It may be necessary to zoom in on some of the graphics within the body of the text below for better legibility.  If you are running 32 bit Microsoft Access under 64 bit Windows, and wish to output the data in a Tableau view to 32 bit Microsoft Access, please read the Appendix to this post before proceeding. Supporting files and a README file are available for download at the end of the second part of the post. Please look at the README file first.

    The author would like to thank Leonid Koyfman for his suggestions.

    Here is part one:

    In the Bar Graph View below (based on the Superstore dataset that comes with Tableau), yearly sales are summed and colored by profit and sized by discount:

    Superstore View

    Reference lines show average sales within each region and customer segment by year for all categories.

    How can we “capture” the data in this view and save it in a database for further analysis and re-use?

    Tableau does let you view underlying data and copy it to the clipboard, export it to a text file, or even a Microsoft Access database, but these are manual operations. What if you could write a Tableau Calculated Field to export the underlying data in a Tableau View to any Database Server that supports the ODBC protocol?

    You can, using R, and an R language library called RODBC.

    Tableau opened the door to using R language libraries within Calculated Fields in version 8.1. This article walks you through downloading and installing R on a desktop computer, configuring Tableau to use your R installation, and writing the Calculated Fields required to export data from a Tableau view to a database such as SQL Server or Microsoft Access.

    (more…)