Direct Query in Power BI

13 June 2023
Eugene Lebedev

Eugene Lebedev is a Power BI consultant by background. Before founding Vidi Corp in 2021 he created Power BI reporting for Autodesk. His Power Bi reports were used by VPs of Finance and C-suite of Autodesk. As part of Vidi Corp, Eugene created dashboards for Google, Teleperformance, Delta Airlines and 200+ clients worldwide.

Introduction

Power BI has become a potent tool for data analysis and visualisation in the realm of business intelligence. Power BI’s ability to use Direct Query to connect directly to data sources is one of its distinguishing characteristics. An in-depth discussion of Power BI’s Direct Query concept, along with its advantages and how it facilitates real-time insights for data-driven decision-making, is provided in this article.

Understanding Direct Query

Direct Query is a connection mode in Power BI that allows you to query data directly from the source system in real time. Unlike other connection modes such as Import or Live Connection, where data is imported or cached in Power BI, Direct Query retrieves data dynamically, ensuring that the analysis is based on the most up-to-date information.

Benefits of Direct Query

  • Real-Time Insights: By leveraging Direct Query, organizations can obtain real-time insights into their data. This is particularly valuable in scenarios where data is constantly changing, such as monitoring live sales data, stock market trends, or operational metrics.
  • Less Data Redundancy: With Direct Query, there’s no need to duplicate or import large datasets into Power BI. Instead, the data remains in the source system, eliminating the need for additional storage and ensuring data consistency across reporting and analysis.
  • Better Data Governance: Direct Query promotes data governance by ensuring that users are always accessing the latest data from the authoritative source. This eliminates concerns about data discrepancies or outdated information caused by data duplication or import processes.
  • Data Transformations: Direct Query allows for complex data transformations to be performed directly in the source system. This can be advantageous when dealing with large datasets or intricate business logic that may not be easily replicable within Power BI.
See also  How to Share power BI report with external user without license

Direct Query Mechanism in Power BI

The query you make in the Power BI interface is sent directly to the underlying data source, like a relational database or an Analysis Services model, when you use DirectQuery. Instead of using Power BI’s own engine (SQL Profiler), the data source itself retrieves and processes the data. Here’s a high-level overview of how DirectQuery works in Power BI:

ConnectionQuery CreationQuery TranslationQuery ExecutionVisualisationReal-Time Updates

Connection: You establish a connection to the data source using one of the supported connectors. Power BI supports various data sources, including SQL Server, Oracle, MySQL, and many others.

Query Creation: You create your queries using Power BI’s query editor or the Query Builder. These queries can include filtering, sorting, aggregating, and joining operations, similar to the data transformation operations performed in Power Query.

Query Translation: Power BI translates the queries you create into the appropriate syntax for the underlying data source. The specific translation process depends on the data source and its query language.

Query Execution: The translated query is sent directly to the data source. The data source processes the query and returns the requested data to Power BI.

Visualisation: Power BI receives the data from the data source and visualises it based on the report or dashboard you’ve designed. You can create various visualisations, apply filters, and interact with the data in real time.

Real-Time Updates: As you interact with the visualisations or apply additional filters, Power BI sends additional queries to the data source to retrieve the updated data. This allows you to explore and analyse the data in real time, reflecting any changes made in the data source.

See also  Boost Your Shopify Store Analytics with Power BI: A Comprehensive Guide

Import vs DirectQuery in Power BI

FeatureImportQuery
Data StorageData is stored within Power BIData stays in the source system
Data RefreshManual or scheduled refresh requiredReal-time or on-demand refresh
Data VolumeLimited by Power BI capacityNo limitation on data volume
Data TransformationExtensive data transformationLimited data transformation capabilities
Data SecurityData resides in Power BI serviceData stays in the source system, maintaining security measures of the source system
CompatibilitySupports a wide range of data sourcesLimited to supported DirectQuery data sources
Query ComplexityCan handle complex queriesLimited ability to handle complex queries
Custom CalculationsCalculations performed within Power BICalculations performed in the source system

Considerations and Limitations

While Direct Query offers significant advantages, it is important to consider some key aspects and limitations:

Performance: Real time querying can impact performance, especially when dealing with large datasets or complex queries. It is crucial to optimise the underlying data source and ensure efficient indexing and query performance for optimal results.

Compatibility with Data Sources: Not all data sources support Direct Query. Power BI has a wide range of supported data sources, but it’s important to verify compatibility before choosing Direct Query as the connection mode.

Data Refresh: When using DirectQuery, a report or dashboard will always display the most recent data from the source when it is opened or refreshed. Additionally, the dashboard tiles may be refreshed as regularly as once every 15 minutes.

Query Folding Limitations: Direct Query relies on query folding, which means that certain transformations performed within Power Query Editor may not be compatible and will be executed in Power BI instead. This can impact performance and data retrieval.

See also  Create QuickBooks Online Reports in Power BI in 5 Mins

Limited Power BI Features: Direct Query has some limitations when it comes to certain Power BI features, such as aggregations, calculated tables, and some visualisation options. It’s important to understand these limitations and determine if they align with your reporting requirements.

Single Query Rows Limit: The maximum number of rows that can return from a single query to the underlying source is 1 million. Visuals won’t show that many points and this limit typically has no practical repercussions. The restriction can, however, appear in Power BI sends queries that aren’t entirely optimized and demands some intermediate result that goes over the limit. You still can work around this limit if you split your data extract into multiple queries.

Common Data Sources Support Direct Query

Unlike import mode, not all the data sources support Direct Query. Here is a list of some commonly used data sources supported by Power BI for Direct Query:

Azure SQL DatabaseAzure Synapse AnalyticsSQL Server Database
Oracle DatabaseSalesforceSAP HANA
Spark  (Version 0.9 and above)SnowflakeAmazon Redshift
Azure Analysis ServicesTeradata DatabaseGoogle BigQuery
SAP Business WarehouseIBM NetezzaAzure HDInsight Spark

DAX Function in Direct Query Mode

When using DirectQuery mode in Power BI, there are certain DAX functions that are not supported directly and cannot be used in calculations within the report. Here is a list of some commonly used DAX functions that are not supported in DirectQuery mode:

SUMXAVERAGEXMAXX
TOTALMTDISBLANKEXACT
RANKXROWFORMAT
ISTEXTISNUMBERISERROR

Best Practices of Direct Query

To make the most of Direct Query in Power BI, consider the following best practices:

Optimise Data Sources: Ensure that the underlying data sources are properly optimised for efficient querying and performance. Implement appropriate indexes and query-tuning techniques to enhance data retrieval speed.

Query Folding and Filtering: Leverage query folding by applying filters and transformations directly in the source system whenever possible. This helps reduce the data transferred between Power BI and the source, improving performance.

Aggregations and Summarisation: Explore the use of aggregated tables or materialised views in the data source to enhance performance and query speed, especially for large datasets. Aggregations can help pre-calculate and store summarized data for faster retrieval.

Consider Import or Composite Models: Depending on the reporting requirements, it may be beneficial to use Import or Composite models instead of Direct Query. Import mode allows for caching and pre-processing data, while Composite models offer a combination of Direct Query and Import modes.

Conclusion

This article has highlighted the benefits and limitations of using a Direct Query connectivity mode. Direct Query gives Power BI users flexibility and real-time analysis capabilities. When selecting whether to use Direct Query as connectivity mode, it’s critical to take into account the performance, compatibility, and restrictions of both the data source and Power BI itself.

Microsoft Power Platform

Everything you Need to Know

Of the endless possible ways to try and maximise the value of your data, only one is the very best. We’ll show you exactly what it looks like.

To discuss your project and the many ways we can help bring your data to life please contact:

Call

+44 7846 623693

eugene.lebedev@vidi-corp.com

Or complete the form below