How to Get SQL Query from Tableau Report

Cody Schneider••8 min read

Ever drag and drop fields in Tableau to build the perfect visualization, then wonder what’s happening behind the scenes? Tableau is translating your actions into SQL queries to fetch data from your database. This article will show you exactly how to find and look at those queries. We'll cover the most reliable method using the Performance Recorder, plus a couple of other techniques for more advanced situations.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Why Look at the SQL Tableau Generates?

Peeking under the hood might seem like a technical chore, but it's an incredibly useful skill for anyone who wants to move from a casual Tableau user to a power user. Understanding the underlying SQL gives you a massive advantage in troubleshooting, optimizing, and even expanding your data analysis capabilities.

Troubleshoot and Validate Your Data

Is that filter really applying correctly? Are the numbers in your chart matching what you'd expect from the raw data? Viewing the SQL query is the ultimate way to confirm how Tableau is interpreting your filters, joins, and calculations. You can see precisely which tables are being queried and which WHERE clauses are being applied, helping you identify why a dashboard might be showing unexpected results.

Tune Dashboard Performance

If a dashboard loads slowly, an inefficient query is often the culprit. By examining the SQL, you can spot performance bottlenecks. Tableau sometimes generates complex subqueries or inefficient joins that a human analyst could simplify. By identifying the slow parts of the query, you can work to optimize your database (e.g., adding an index) or restructure your Tableau data source to generate more efficient SQL.

Reuse Queries Elsewhere

Once you’ve built a complex view in Tableau, you might want to reuse that exact same data pull in another tool - a Python script, another BI application, or even just running it directly against the database for a one-off report. Instead of rebuilding the logic from scratch, you can just copy the SQL that Tableau has already perfected for you, saving a huge amount of time.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Learn SQL the Practical Way

For those new to SQL, there's no better teacher than observing an expert. Watching how Tableau constructs queries as you add filters, create groups, or blend data is a fantastic, hands-on way to learn SQL syntax. You'll see how LEFT JOINs, GROUP BY clauses, and complicated filters are written in the real world, which is often more illuminating than any textbook example.

Method 1: The Performance Recorder (The Best Way)

The most direct and reliable way to see the SQL query for a specific worksheet is by using Tableau’s built-in Performance Recorder. It’s designed to help you analyze workbook performance, and a key part of that analysis is showing you the exact queries being sent to your database.

Follow these steps:

  1. Start Recording: Navigate to the top menu and select Help > Settings and Performance > Start Performance Recording.
  2. Trigger a Query: After you start recording, Tableau will now log all activity. Now, you need to force Tableau to query the database. Go to the dashboard or worksheet you're interested in and interact with it. You could refresh the data source, apply a filter, or even just open the worksheet for the first time. The key is to perform an action that makes the view update.
  3. Stop Recording: Once the view has loaded or updated, go back to the menu and select Help > Settings and Performance > Stop Performance Recording.

A new Tableau workbook will automatically open. This is your performance summary dashboard, and it's full of valuable data.

Interpreting the Performance Recording

The performance dashboard can seem a bit intimidating at first, but you only need to focus on one section.

  • Look for the dashboard called "Events Sorted by Time."
  • In this view, find the event called "Executing Query." There might be several, but the longer bars usually represent the more significant queries pulling data for your visualizations.
  • Click on one of the "Executing Query" bars.
  • Below the timeline, a text box will appear. In that box is the exact SQL query that Tableau sent to your data source.

You can now highlight this text, copy it, and paste it into any SQL editor, text file, or analysis tool to examine or reuse it. It’s that simple!

Method 2: Manually Reading the Tableau Log Files

For those who need to see everything or who can't use the performance recorder for some reason, there's a more advanced backup plan: the log files. Tableau keeps detailed logs of its operations, and that includes every single query it runs.

Be warned: this is like drinking from a firehose. The logs are verbose and packed with technical information, but they are a goldmine if you know what to look for.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Where to Find the Log Files

The log files are stored in your "My Tableau Repository" folder. The direct path is usually:

  • On Windows: C:\Users\[Your Username]\Documents\My Tableau Repository\Logs
  • On Mac: /Users/[your user]/Documents/My Tableau Repository/Logs

The main file you’re looking for is usually named log.txt. There may also be older, archived log files (like tabprotosrv.txt depending on your connection), but log.txt will have the most recent activity.

How to Search the Log Files

Open log.txt in a text editor (like Notepad++, VS Code, or Sublime Text works best as they can handle large files better than standard Notepad). The file will be huge, so you'll need to use the search function.

Search for keywords that mark the start and end of a query. In most cases, queries are wrapped in XML-like tags:

<begin-query> ... (your SQL query will be here) ... </end-query>

Simply search for the phrase <begin-query>. The text following that tag, right up until you see </end-query>, is the SQL that was executed. This method is comprehensive but requires patience to sift through the noise to find the specific query you're after.

Key Things to Remember: Potential Pitfalls

As you start pulling queries from Tableau, you’ll run into a few common scenarios that can be confusing. Here’s what you need to know.

Live Connection vs. an Extract

This is the most important distinction. You will only see standard SQL for data sources with a Live Connection.

If you're using a Tableau Extract (a .hyper or .tde file), the data has already been pulled from the database and optimized for Tableau's internal engine. When you work with an extract, Tableau uses its own internal query language to retrieve data, not SQL. If you run the Performance Recorder against an extract, you’ll see commands like "end-prepare-query" or "compute-tuple" instead of a clean SELECT statement. If you're not seeing SQL, double-check your data source connection type first.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Custom SQL is a Different Beast

If you created your Tableau Data Source using the "Custom SQL" option, what you see in the Performance Recorder will be slightly different. Tableau will take the Custom SQL you already wrote and wrap it in another query. The Performance Recorder will show you this "outer" wrapper query, which often looks something like:

SELECT [CustomSQL_1].[field1] AS [field1], ... FROM ( your custom SQL query lives here ) AS [CustomSQL_1]

This is expected behavior. Tableau does this to apply its own filters and aggregations on top of the base result set returned by your initial SQL code.

Table Calculations Don't Happen in SQL

If your view uses Table Calculations (like PERCENTOF, RUNNING_SUM, or WINDOW_AVG), you won't find them in the generated SQL. Table Calculations are performed by Tableau after the data is retrieved from the database. The SQL query simply pulls the base data, Tableau's own processing engine then handles the final computations.

Final Thoughts

Learning how to extract the SQL from your reports is a game-changer for mastering Tableau. Whether you use the simple Performance Recorder or dig into the log files, this skill empowers you to debug issues, fine-tune slow dashboards, and deeply understand how your beautiful vizzes get made from raw data.

Peeking behind the curtain in Tableau to find the SQL is useful, but it also highlights the inherent complexity of traditional dashboards. That's why we built Graphed. Instead of wrestling with a drag-and-drop interface and then having to dig up the query to troubleshoot it, you just describe what you want in plain English. Ask "show me a sales trend from Shopify for the last two quarters filtered by social media campaigns," and we run the query, build the visualization, and generate the dashboard for you - all from a single sentence. It connects to your data sources in real-time, allowing you to focus on the insights, not just how the report is built.

Related Articles