Microsoft Power BI

How To Capture SQL Queries Generated By Power BI?

Suppose one uses the DirectQuery option for more than one table in their Power BI dataset. In that case, they’ll probably want to view the SQL (or query language used in the Direct Query) that Power BI generates when the report is run. If the user can view the queries executed in one of the data source’s tools, such as Extended Events or SQL Server Profiler for SQL Server, it is a fantastic thing – but the user will not be able to have the permissions to do so. The good news is that it is easy to capture SQL queries in Power BI Desktop, albeit it’s not always evident how to do the same. Before understanding the intricacies, let us examine SQL and Power BI.

What is SQL?

SQL is an acronym that is used for Structured Query Language. It is a database management and communication language that is being used for various purposes. For instance, one can use database creation, deletion, and updating rows by fetching and altering records. In addition, SQL statements are used to perform operations such as changing or obtaining data from a database.

It is a standard language, and it gets it from the ANSI (American National Standards Institute). Other SQL language variations consist of various things, including T-SQL by Microsoft, PSQL by Interbase/Firebird, and many others. Consequently, when we talk about the most prevalent SQL-based relational database management systems, it consists of various methods, including Sybase, Microsoft SQL Server, Oracle, Ingres, Access, and many others. Even though a significant chunk of these database systems uses SQL, most of them come with extra proprietary extensions explicitly designed for their system’s operation. You can use SQL Online Training and join the course and improve your skills in this field.

Major Advantages of SQL

  1. It is a common querying language

As we all are aware, SQL is a standard when it comes to database language. All sorts of database programs these days get the best out of it. (We can take the example of SQL Server, MYSQL, SQLite, etc.)

  1. Simple to learn

SQL has always been considered a simple language. This is because SQL uses simple English-like language statements; this makes most people with a rudimentary understanding of SQL readily grasp it. Also, since SQL is an open-source tool, learning resources become easily accessible to users.

  1. Simple and effective approaches

SQL is considered to be a fast technique when it comes to working with data. With the use of basic searches, one can get quite complex results. This basic querying approach has made data analysis, modification, and testing more accessible, faster, and reliable.

What does one understand by Queries?

A query can request information or data from a database table or simply databases. This sort of data may get its creation in the form of Structured Query Language (SQL) outputs or in the form of pictorials, graphs, or complicated outcomes like trend analysis by using data-mining tools.

Suppose one wants to run a variety of simple and complicated database queries; they will use the most common query languages. Many database managers are well versed with SQL, one of the most famous and commonly used query languages (DBAs).

What is Power BI?

Microsoft Power BI is a business analytics tool that allows the user to get a visualization of data and also allows them to share insights throughout their organization. It also allows one to integrate them into an app or website. The solution consists of many different goods and services, and the value and adaptability derive from exploiting the separate pieces and capitalizing on how they interact with each other and others.

Significant Advantages of Power BI

  1. Seamless integration with existing applications:

Power BI does not face any issues while integrating with your existing business environment. This gives you, as a user, an opportunity to embrace analytics and reporting capabilities. Microsoft Azure experts also provide extensive assistance in utilizing this simple technology if you wish to include dynamic visualizations in your website or apps.

  1. Richly personalized Dashboards:

The information dashboard can get unique customizations to match the individual needs of every organization. This is primarily the distinguishing feature of Power BI. Dashboards and BI reports, which may get a ready inclusion when it comes to apps and give you a consistent user experience.

  1. Securely publish reports:

The tool enables you to do a variety of configurations for automatic data refresh and the publication of reports. This process is carried out while ensuring that all users get equal access to the most up-to-date information.

  1. There is no requirement for specialized Tech support:

With the help of power BI, one gets an agile inquiry as well as analysis without taking the help of any technical tech support. It has a support system of a powerful natural language interface, and it also uses an intuitively graphical designer tool.

  1. It can extract business intelligence rapidly and precisely:

With the help of Power BI, one can transform enterprise data into rich visuals, which also lets the user extract business intelligence to make better decisions.

What are the features of DirectQuery?

  1. With the help of DirectQuery, one can build a visualization over a large chunk of datasets. In other scenarios, it might seem entirely unfeasible to first import all the data along with the process of pre-aggregation.
  1. Underlying data changes may require the necessitation of a data update. A lot of reports require significant data transfers if one wants to present the current data; this makes the process of reimporting data impossible. With the help of DirectQuery words, on the other hand, it is crucial always to utilize current data.
  1. DirectQuery is exempt from the rule that there is a 1-GB dataset restriction.

The process to Capture SQL Queries Generated by a Power BI DirectQuery Dataset.

If we look at some data sources, such as SQL Server, Performance Analyzer will display the SQL queries that are generated. Therefore, all the user needs to do is navigate to the View tab in the main Power BI Desktop window. After that, they need to click on the Performance Analyzer button to get the display of the Performance Analyzer pane; following that; the user needs to click on Start Recording and then Refresh Visuals. Next, the user must locate the event corresponding to the visual queries they want to view. After discovering, there is a need to expand it, and then the last step is to select the “Copy query” link.

This transfers the DAX query created by the user’s visual to the clipboard. In addition, it also results in moving the SQL query generated for that DAX query, specifically regarding SQL Server DirectQuery sources.

This solution, however, is not compatible with all the DirectQuery data sources. For those other cases, one can utilize the Query Diagnostics capability contained in the Power Query Editor. First, the user must open the Power Query Editor window, navigate to the Tools tab on the ribbon, and then click the Start Diagnostics button. After that, it is essential to return to the main Power BI window, refresh the visuals (using the Refresh visuals button in Performance Analyzer), and then return to the Power Query Editor. As the final step, the user must select the Stop Diagnostics button.

Multiple additional Power Query queries surface with diagnostics data when the user does this. The process that one needs to follow after that is to go to the one that has a name that begins with “Diagnostics Detailed,” and there, the user can find the query created somewhere in there. The exact location of the question depends on the data source. For instance, the SQL made will be displayed anywhere in the Data Source Query column regarding the Snowflake data source. Regarding an Azure Data Explorer DirectQuery data source, the KQL query will be contained in one of the numerous Record values in the Additional Info column. The user needs to keep an eye out so they may also see what might present themselves as SQL Server TSQL queries, even when the user is not using any data source that can get its query from TSQL.


There are various ways in which a user can capture SQL queries that Power BI generates. Therefore, there is no reason to worry if the DBA comes to your desk. You have all the abilities to provide all the critical information relating to fine-tuning SQL queries on the source side. Visit here for Power BI Certification Course.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *