How to Get Query from Tableau Report
Ever look at a beautiful, insightful Tableau dashboard and wonder, "What exact data pull is making this chart work?" You know the data is correct, but you need the underlying SQL query to debug a different report, validate the logic, or reuse it somewhere else. This article will show you three effective methods to pull the exact query Tableau sends to your database, from the simplest click-of-a-button approach to more advanced techniques for surgical precision.
Why Would You Need to Get a Query from Tableau?
Before jumping into the "how," it’s helpful to understand the "why." Extracting the SQL from a Tableau viz isn't just a technical exercise, it solves several real-world problems that marketers, analysts, and business owners face every day.
- Debugging and Validation: The chart says you had 1,500 new leads last month, but another system says 1,450. Which one is right? By running the exact query Tableau uses directly against your database, you can confirm the raw numbers and pinpoint discrepancies in the logic.
- Reusing Logic: A colleague built the perfect dashboard calculating customer lifetime value. You want to use that same calculation in a dedicated product analytics tool or an automated email report. Pulling the query gives you the business logic so you don't have to reinvent the wheel.
- Performance Tuning: Is a specific dashboard loading incredibly slowly? Extracting the query allows you or a database administrator to analyze it, identify bottlenecks, and optimize its performance, making the dashboard faster for everyone.
- Migration Projects: If your team is moving from Tableau to another BI tool, you'll need to replicate dozens of reports. Having the source queries makes this process monumentally faster than trying to rebuild every visualization from scratch just by looking at it.
- Documentation: Creating a data dictionary or documenting business logic? The underlying queries are the ground truth for how your critical key-performance indicators (KPIs) are calculated.
Method 1: The Go-To Approach with Performance Recording
For most day-to-day needs, Tableau’s built-in Performance Recorder is the quickest and cleanest way to find the query for a specific visualization. It was designed to help users identify slow-performing elements in a workbook, but its superpower is capturing every single query that gets fired when you interact with your dashboard.
Here’s how to use it step-by-step:
Step 1: Start the Performance Recording
With your Tableau workbook open, navigate to the top menu bar. Just two clicks get you started:
Go to: Help > Settings and Performance > Start Performance Recording
Once you click this, Tableau starts logging everything it does in the background, including connecting to data sources, running calculations, and, most importantly, executing queries.
Step 2: Interact with Your Visualization
Now, navigate to the specific worksheet or dashboard you want to capture the query for. To ensure the query runs while being recorded, you need to trigger an update. Here are a few ways to do that:
- Press F5: The simplest way is to just refresh the data source, which forces Tableau to re-run the queries for the view.
- Change a filter: Apply a new filter or modify an existing one. This action sends an updated query to the database.
- Interact with the dashboard: Click on a mark, use a highlighter action, or sort a bar chart. Any interaction that causes the visualization to update will likely trigger a query.
The goal is to perform the exact action that generates the data you're curious about.
Step 3: Stop the Performance Recording
Once you’ve interacted with the dashboard, head back to the same menu:
Go to: Help > Settings and Performance > Stop Performance Recording
The moment you click "stop," Tableau will automatically open a new workbook. This workbook contains the performance recording dashboard itself - a detailed, pre-built Tableau dashboard analyzing the actions you just took.
Step 4: Find and Copy Your Query
The performance dashboard can look a bit intimidating at first, but it’s easy to navigate once you know what you’re looking for. It has three main sections: Timeline, Events, and Query.
Focus on the middle pane called "Events," which shows a table of all the events that occurred, sorted by duration. Here’s what to do:
- Look for events named "Executing Query." These are the actual queries Tableau sent to your database. There might be several, especially on a complex dashboard.
- Click on one of the "Executing Query" events that corresponds to the viz you interacted with.
- Once you click it, the bottom pane, labeled "Query," will populate with the full SQL query text.
You can now see the complete query. It might be long and complex, but all you have to do is click inside the text box, select all the text (Ctrl+A or Cmd+A), and copy it to your clipboard. You’ve successfully extracted the query!
Method 2: The Deep Dive into Tableau's Log Files
Sometimes, the Performance Recorder isn’t an option. Maybe the query is running as part of an initial load that's hard to capture, or you just prefer getting your hands dirty. In those cases, you can dive directly into Tableau's local log files. Tableau Desktop logs nearly everything it does, and that includes every query it generates.
This method feels more technical, but it’s just a matter of knowing where to look.
Step 1: Locate Your "My Tableau Repository" Folder
Tableau stores its logs and other files in a dedicated repository on your computer. The location is standard:
- On Windows: Navigate to
C:\Users\[Your Username]\Documents\My Tableau Repository\Logs - On macOS: Navigate to
/Users/[Your Username]/Documents/My Tableau Repository/Logs
Step 2: Identify the Right Log File
Inside the Logs folder, you'll see several files. For extracting queries generated by Tableau Desktop, the file you want is typically named log.txt. This file contains the most recent operational logs from your current or last session. You might also see files like tabprotosrv.log (which handles protocol-level communications with data sources), but log.txt is usually your best bet for the SQL itself.
Step 3: Trigger the Query and Open the Log
To avoid sifting through tons of old log entries, it helps to start a "clean" session.
- Close Tableau Desktop completely. This ends the current logging session.
- Re-open Tableau Desktop and the specific workbook you are analyzing.
- Interact with a viz or refresh the data source to ensure the query you want is executed.
- Now, navigate to your Tableau Repository's
Logsfolder and openlog.txtwith a text editor like Notepad, TextEdit, VS Code, or Notepad++.
Step 4: Search for the Query in the Log Text
Log files are verbose, so you don't want to read them line by line. Use the search function (Ctrl+F or Cmd+F) in your text editor. Here are a few terms to search for to quickly find the queries:
begin-query: This text string often appears right before a block of SQL is logged. It’s a great marker to jump to."query": Look for the JSON key"query":followed by the SQL statement in quotes.- Specific Table/Column Names: If you know the query should select from a
userstable, for example, just search forusers.
You'll probably find a lot of system-level queries ("discovery queries") that Tableau uses to understand the database schema. Keep searching until you find the SELECT statement that contains the fields and logic you recognize from your visualization.
Method 3: Go Straight to the Source with Database Tools
This is an advanced but foolproof method for users who have direct access to the database that Tableau is connected to (e.g., SQL Server, PostgreSQL, BigQuery). Instead of asking Tableau what query it sent, you ask the database what query it received. This is the ultimate source of truth.
Every major database has logging or monitoring tools that can show you the queries that are currently running or were recently run.
Example: SQL Server
If you're connected to Microsoft SQL Server, you can use SQL Server Profiler. You can start a trace and set a filter so it only shows you activity coming from the "Tableau" application or from your specific database username. When you interact with your Tableau workbook, you'll see the exact queries pop up in the Profiler window in real-time.
Example: PostgreSQL
For PostgreSQL, you can enable logging of all queries within the postgresql.conf file by setting log_statement = 'all'. Or, for a quick look at live queries, you can run this command to see what’s actively running:
SELECT pid, usename, client_addr, state, query
FROM pg_stat_activity
WHERE application_name = 'Tableau',Example: BigQuery
In Google BigQuery, every query executed is recorded in the Job History. You can open the BigQuery console, navigate to "Query history," and see a detailed log of all queries run against your datasets, including those generated by Tableau. They are typically identifiable by the job ID prefix related to the BI connector.
Using these tools requires database access, but it's incredibly powerful for situations where you need to see exactly what hits your database, stripped of any abstractions from Tableau.
A Quick Note on Tableau-Generated SQL
One final word of caution: the SQL you extract from Tableau might not look like the clean, handwritten code you'd write yourself. Tableau’s query generator (its internal engine known as VizQL) prioritizes accuracy and performance over readability.
You'll often see:
- Multiple nested subqueries.
- Heavy use of
CASEstatements for calculations created in Tableau. - Creation and use of temporary tables (e.g.,
#Tableau_1_........). - Complex window functions for table calculations.
Don't be alarmed! This is normal. The query is correct, but you may need to spend a minute in a formatting tool or text editor to tidy it up if you plan to share it with your team.
Final Thoughts
Extracting SQL from a Tableau report is a fundamental skill for anyone who wants to move beyond just viewing dashboards and start truly understanding or extending their data. Whether you use the simple Performance Recorder, dig into the log files, or monitor the database directly, these methods give you a backstage pass to see exactly how your data visualizations are created.
While these techniques are powerful for working inside of Tableau, they also highlight the manual work often needed to answer questions with traditional BI tools. We created Graphed because we believe getting insights shouldn't require you to become a query detective. Instead of digging through logs, you can connect your data sources in one click and use plain English to build real-time dashboards, pull reports, and get your questions answered in seconds.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.