How to See Query Behind Power BI Report
Ever stared at a Power BI visual and felt sure the number it was showing couldn't be right? Peeking behind the curtain at the underlying query is your first step to solving the puzzle and gaining full control over your reports. This article will show you exactly how to find the queries Power BI generates so you can troubleshoot errors, optimize performance, and understand what’s truly happening with your data.
Why Bother Looking at the Query?
You might think that if you drag-and-drop your way to a report, you should never have to look at code. But knowing how to access the queries Power BI runs in the background is a game-changer. It’s the difference between guessing what’s wrong and knowing what's wrong.
Here’s why it’s worth your time:
- Troubleshooting and Debugging: This is the number one reason. When a chart, table, or card visual displays unexpected results, the query behind it reveals the exact logic being used. You can see precisely how filters are being applied and what calculations are happening, which often immediately highlights the source of the problem.
- Performance Optimization: Is your report painfully slow to load or refresh? Inefficient queries are almost always the culprit. By examining the DAX (Data Analysis Expressions) queries generated by your visuals, you can identify performance bottlenecks. Sometimes a small change in your data model or DAX measures can slash loading times.
- Learning and Deeper Understanding: Watching what Power BI does behind the scenes is one of the best ways to learn both M (in Power Query) and DAX. You can see how the interface translates your clicks into actual code, which deepens your understanding of how everything connects and works together.
- Reusing and Auditing Logic: Have you created a particularly complex calculation in a visual that you want to reuse elsewhere? You can copy the DAX query and adapt it. It's also perfect for auditing a report built by someone else, you can review their calculations to validate the logic without having to deconstruct every visual manually.
Method 1: Finding the M Query in Power Query Editor
Before a DAX query can even run, your data has to be loaded and transformed. This process is handled by Power Query, and the language it uses is called M. Every step you take in the Power Query Editor - removing columns, filtering rows, changing data types - is recorded as a line of M code. Seeing this code is straightforward.
The M query tells the story of your data’s journey from its original source into your Power BI data model. Here’s how to view it step-by-step.
Step 1: Open the Power Query Editor
From your main Power BI Desktop window, go to the Home tab on the ribbon and click on Transform data. This will launch the Power Query Editor in a new window.
Step 2: Select a Query
On the left side of the Power Query Editor, you'll see a pane labeled Queries, which lists all the data tables you’ve connected. Click on the one whose transformation steps you want to investigate.
Step 3: Open the Advanced Editor
With your desired query selected, navigate to the View tab in the Power Query ribbon at the top of the window. On that tab, you will find and click the Advanced Editor button.
This will open a new window showing the complete M code for that specific query. Each transformation stage - connecting to the source, changing data types, filtering rows - is laid out sequentially.
Example M Code
The code inside might look something like this. Even if you don't know M, you can often read the steps and understand the transformation logic.
let
Source = Csv.Document(File.Contents("C:\Users\YourUser\Documents\SalesData.csv"),[Delimiter=",", Columns=4, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"OrderID", Int64.Type}, {"Product", type text}, {"Date", type date}, {"Revenue", Currency.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Revenue] > 100)
in
#"Filtered Rows"Here, you can clearly see it connected to a CSV file, promoted the first row to headers, changed the data types of four columns, and then filtered the table to only include rows where the revenue was greater than 100.
Method 2: Capturing the DAX Query with Performance Analyzer
Once your data is loaded into the model, your report visuals query that model using DAX. Every slicer you click and every chart that loads generates a DAX query on the fly. The best built-in tool for seeing these queries is the Performance Analyzer.
This handy tool logs everything that happens on your report page, including the exact DAX query sent by each visual. It is invaluable for troubleshooting and optimization.
Step 1: Open the Performance Analyzer
In Power BI Desktop, navigate to the View tab on the main ribbon. Click the checkbox for Performance Analyzer. A new pane will appear on the right side of your screen.
Step 2: Start Recording
In the Performance Analyzer pane, click the Start recording button. Power BI will now begin monitoring all actions and their performance impact.
Step 3: Interact with Your Report
Now, interact with your report visuals as a user would. An easy way to capture everything on a page is to click Refresh visuals in the Performance Analyzer pane. You can also click on slicers or cross-highlight charts to see how those interactions generate new queries.
As you do this, you'll see a log of every action for each visual appear in the pane, breaking down the time taken for the DAX query, visual display, and other processes.
Step 4: Copy the DAX Query
Find the visual you're interested in within the Performance Analyzer list and click the small plus sign (+) to expand its details. You'll see an entry labeled DAX query.
Below the query text box, there's a Copy query link. Click it, and the full DAX query for that visual will be copied to your clipboard. You can then paste this into a text editor like Notepad, VS Code, or a dedicated DAX formatter to see it more clearly.
Example DAX Code
The copied query might be long and unformatted, but it contains all the logic. It will often begin with EVALUATE and SUMMARIZECOLUMNS.
// DAX Query
EVALUATE
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL(
'Date'[Calendar Year], "IsGrandTotalRowTotal"
),
"Total_Revenue", CALCULATE(SUM('Sales'[Revenue]))
)
ORDER BY
'Date'[Calendar Year]By reading this query, you can confirm the visual is calculating the sum of the 'Sales'[Revenue] column and grouping it by 'Date'[Calendar Year], a perfectly standard and simple operation. If it were instead showing a COUNT or filtering by an unexpected product category, you would find that logic here.
Method 3: Go Pro with DAX Studio
While the Performance Analyzer is great for a quick look, serious Power BI developers use a powerful free external tool called DAX Studio. It connects directly to your Power BI data model and gives you a much richer environment for writing, running, and analyzing DAX performance.
Using DAX Studio is an advanced technique, but it gives you superpowers:
- Live Query Tracking: You can trace everything happening in your Power BI file in real time. Click a slicer in Power BI, and the exact DAX query generated instantly appears in DAX Studio.
- Detailed Performance Metrics: Unlike Power BI, DAX Studio can tell you not just how long a query took, but why. It breaks down the time spent in the Storage Engine (SE) versus the Formula Engine (FE), which is critical for advanced optimization.
- Better Formatting and Writing: It has built-in formatters that turn messy, unreadable DAX into clean code, not to mention a full-featured editor for writing and testing queries from scratch.
To use it, you download and install DAX Studio, then launch it. It will automatically detect any open Power BI Desktop files, allowing you to connect in one click. From there, you can navigate to the "All Queries" tab to start tracing report activity. It’s the ultimate tool for digging deep into your report's mechanics.
Final Thoughts
Knowing how to see the query behind your Power BI reports - both the M query for data transformation and the DAX query for visuals - moves you from a report builder to a true analyst. It gives you the power to diagnose issues with certainty, optimize slow reports, and fully understand the data logic from end to end. Mastering the Performance Analyzer and Advanced Editor is a must-have skill for serious development.
This process of building, troubleshooting, and optimizing queries is essential but often requires learning complex languages like DAX. We created Graphed to remove this friction entirely. Instead of spending hours clicking around an interface just to dig for queries later, you can describe the dashboard you need in plain English. Graphed connects directly to your tools like Google Analytics and Salesforce, building real-time dashboards for you in seconds without requiring you to write a single line of code.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
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.