{"id":4251,"date":"2023-02-21T14:13:47","date_gmt":"2023-02-21T14:13:47","guid":{"rendered":"https:\/\/www.biconnector.com\/blog\/?p=4251"},"modified":"2023-05-18T05:16:29","modified_gmt":"2023-05-18T05:16:29","slug":"query-folding-power-bi-everything-you-need-to-know","status":"publish","type":"post","link":"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/","title":{"rendered":"Query Folding in Power BI: Everything you need to know"},"content":{"rendered":"\n

Query folding is a powerful feature in Power BI that can significantly enhance your data analysis capabilities. To maximize its benefits, it’s essential to have a clear understanding of what it is and how it works. This article will provide a comprehensive guide to query folding in Power BI, covering everything you need to know.<\/p>\n\n\n\n

What is Query Folding?<\/h2>\n\n\n\n

Query Folding is the capability of a Power Query to create a single statement that can transform and execute tasks (such as filtering a thousand rows of data) on the data source side. Through Query Folding, Power Query can deal with a vast volume of data efficiently.<\/p>\n\n\n\n

Understanding Query Folding<\/h2>\n\n\n\n

You can think of Query folding as writing down a set of instructions in SQL code and passing it over to the database for enforcement. In essence, the data source does the heavy lifting and, in turn, reduces the amount of data that has to be processed and transferred within Power BI. <\/p>\n\n\n\n

Power Query will automatically execute query folding under the following conditions:<\/p>\n\n\n\n

1.\tThe data source is a database that can accept a query request. <\/p>\n\n\n\n

2.\tAll the steps in the configuration must allow query folding. If you perform even a single action that cannot be folded, query folding will stop for the entire query.<\/p>\n\n\n\n

3. The Query must not start with your own SQL code. If you start your query with your own SQL code, no steps in the query will be folded.<\/p>\n\n\n\n

How to Find If Your Power BI Data Source Supports Query Folding?<\/h2>\n\n\n\n

To find if a data source supports Query Folding in Power BI, follow the steps given below:<\/p>\n\n\n\n

1. Right-click your sheet on the Report View in the field pane and select Edit Query<\/strong>. You will be redirected to the Power Query Editor<\/strong>.<\/p>\n\n\n\n

\"Fields<\/figure><\/div>\n\n\n\n

2.Here, on the right, you will be given several transformations. Right-click on any one of them and select View Native Query<\/strong>.<\/p>\n\n\n\n

\"View<\/figure><\/div>\n\n\n\n

3. The dialogue box below shows that Query Folding was performed for this column.<\/p>\n\n\n\n

\"Native<\/figure><\/div>\n\n\n\n

If the View Native Query<\/strong> option was grayed out, it would mean that query folding could not be applied to this step.<\/p>\n\n\n\n

Query Folding Indicators<\/h2>\n\n\n\n

Query folding indicators provide insights into the behavior of a query by determining whether it will fold or not based on the underlying query plan. Below is an image quickly listing the indicator icon along with its meaning.<\/p>\n\n\n\n

\"Query<\/figure>\n\n\n\n

Now let\u2019s see them one by one.<\/p>\n\n\n\n

Folding<\/h3>\n\n\n\n

This indicator indicates that the data source will execute the query up to this step.<\/p>\n\n\n\n

Not Folding<\/h3>\n\n\n\n

This means that the data source will not process certain parts of the query. To maximize performance, it’s important to rearrange the query so that the data source executes as many transformations as possible.<\/p>\n\n\n\n

Might fold<\/h3>\n\n\n\n

This indicator signifies that the folding status cannot be determined beforehand and will be determined during runtime. It only appears when using OData connections or ODBC.<\/p>\n\n\n\n

Opaque<\/h3>\n\n\n\n

This indicator signifies that the query plan is indeterminate and may indicate that the query plan tool and indicators are not supported by the connector.<\/p>\n\n\n\n

Unknown<\/h3>\n\n\n\n

This indicates that the underlying query plan is absent. This could occur due to an error or when you attempt to run the query plan evaluation on something other than a query table. <\/p>\n\n\n\n

The image below shows each indicator with its respective icon:<\/p>\n\n\n\n

Steps to Setup Query Folding
<\/h2>\n\n\n\n

To perform query folding in Power BI, follow the steps below:<\/p>\n\n\n\n

Connect Power BI to a data source:<\/strong> <\/p>\n\n\n\n

1.To perform query folding in Power BI, you must connect to a Power BI data source that supports Query Folding. In our demonstration, we will use Microsoft Access Database. To follow along with this article, download the dataset by clicking here<\/a>. To connect to a data source, click on Get Data<\/strong> and choose the relevant data source. After that, guide the interface to the location of the source.<\/p>\n\n\n\n

\"Connecting<\/figure>\n\n\n\n

2. Load Data:<\/strong> You can now use the Query Editor to perform any edits you want. Click Transform Data,<\/strong> and you will be redirected to the Query Editor.<\/p>\n\n\n\n

\"Transform<\/figure>\n\n\n\n

3. Perform Transformations:<\/strong> Once the Query Editor opens up, you can perform transformations and push them into the data source. It could be as simple as sorting the rows of a particular column in ascending order, as shown below:<\/p>\n\n\n\n

\"Simple<\/figure>\n\n\n\n

You can also perform a more complex transformation, such as adding a conditional column. Go to Add column<\/strong> and click on Conditional column<\/strong>. After that, add a condition as shown below:<\/p>\n\n\n\n

\"Conditional<\/figure>\n\n\n\n

4. Apply the Transformations: <\/strong>On the Home <\/strong>tab, click Close & Apply<\/strong> to load the data onto Power BI. You can also repeat the process for any column on which you want to perform query folding.<\/p>\n\n\n\n

Transformations that Support Query Folding<\/h2>\n\n\n\n

Some of the most common transformations that support query folding are: <\/p>\n\n\n\n

  • Removing or renaming columns<\/li>
  • Merging foldable queries that are based on the same source.<\/li>
  • Appending foldable queries based on the same source.<\/li>
  • Numeric calculations<\/li>
  • Joins<\/li>
  • Pivot and unpivot<\/li><\/ul>\n\n\n\n

    These are only a few examples, and there are numerous additional transformations that support query folding. However, it’s important to note that even though the SQL source is capable of supporting query folding, this does not guarantee that your query will actually fold.<\/p>\n\n\n\n

    The transformations that do not support query folding include: <\/p>\n\n\n\n

    • Merging or appending queries that are based on different sources. <\/li>
    • Using some functions while adding custom columns that do not have a counterpart in SQL. <\/li>
    • Adding columns with complex logic. These refer to functions that do not have equivalent functions in the data source.<\/li><\/ul>\n\n\n\n

      Types of Query Folding<\/h2>\n\n\n\n

      There are three ways a query folding statement could go: <\/p>\n\n\n\n

      1.\tFull query folding:<\/strong> All your transformations are pushed to the source, and processing occurs at the Query engine accordingly. <\/p>\n\n\n\n

      2.\tPartial query folding:<\/strong> This happens when only a part of your transformations is pushed back to the source. Therefore, a part of the processing occurs in the query engine. This is sometimes used when performing some steps that prevent query folding.<\/p>\n\n\n\n

      3. No query folding:<\/strong> This might happen when the Query has transformations that cannot be translated to the language of the data source. This could be because the connector cannot support query folding or the transformations are not supported. Therefore, the Power Query, in this case, gets the raw data and uses the Power query engine for processing.<\/p>\n\n\n\n

      Query folding compatible sources<\/h2>\n\n\n\n

      Some of the data sources that support query folding are given below:<\/p>\n\n\n\n

      • OData feeds<\/li>
      • SharePoint Lists <\/li>
      • Web services<\/li>
      • DirectQuery capable sources like Azure Synapse Analytics, Azure Data Lake Storage, and Azure SQL Data Warehouse<\/li>
      • Exchange<\/li>
      • HDFS, Folder.Contents, Folder.Files<\/li><\/ul>\n\n\n\n

        Query folding non-compatible sources<\/h2>\n\n\n\n
        • Flat files (such as CSV or Excel)<\/li>
        • SharePoint Excel files<\/li>
        • Power Query connections<\/li>
        • Some NoSQL databases like MongoDB or Cassandra <\/li><\/ul>\n\n\n\n

          Importance of Query Folding<\/h2>\n\n\n\n

          Following are some of the importance of Query Folding:<\/p>\n\n\n\n

          Increased Efficiency<\/h3>\n\n\n\n

          Query folding is extremely useful as it makes the whole process very efficient. It sends the data transformation and filter commands to the data source, where it is executed. This reduces the amount of data transferred and processed within Power BI. This results in faster transformation performance in Power BI.<\/p>\n\n\n\n

          Optimization of CPU Usage <\/h3>\n\n\n\n

          Query folding optimizes the use of resources such as CPU usage and memory. By reducing the amount of data processed within Power BI, query folding reduces the pressure on the computer’s resources, leading to minimized risks of crashes and overall better performance. <\/p>\n\n\n\n

          Improved Data Security <\/h3>\n\n\n\n

          In some cases, Query Folding might improve data security as sensitive data is not transferred to Power BI for transformations. It remains secure and protected on the data sources, and all the transformations are applied there.<\/p>\n\n\n\n

          Downsides of Query Folding<\/h2>\n\n\n\n

          Following are some of the downsides of using Query Folding in Power BI:<\/p>\n\n\n\n

          Minimal Support <\/h3>\n\n\n\n

          Query folding is only supported in specific data sources such as SQL servers and Oracle. Others, such as Excel Flat file, would not be able to take advantage of its benefits. This is also true if the said data source has certain restrictions on certain data types or functions. It limits the transformations that can be performed. <\/p>\n\n\n\n

          Complexity<\/h3>\n\n\n\n

          Query folding can sometimes be very complex when dealing with a complex data source with several relationships. In these cases, performing transformations in PowerBI is always a better idea. Debugging Query folding issues can be complex as the data filtering and transformations occur at the source, which makes it very difficult to identify the root cause of the problem.<\/p>\n","protected":false},"excerpt":{"rendered":"

          Query folding is a powerful feature in Power BI that can significantly enhance your data analysis capabilities. To maximize its benefits, it’s essential to have a clear understanding of what it is and how it works. This article will provide a comprehensive guide to query folding in Power BI, covering everything you need to know. […]<\/p>\n","protected":false},"author":19,"featured_media":4378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[112],"tags":[188],"yoast_head":"\nQuery Folding in Power BI: Everything you need to know - BI connector Blog<\/title>\n<meta name=\"description\" content=\"Check out what's Query folding in Power BI, along with the steps to set up query folding for the list of data sources supporting the feature.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Query Folding in Power BI: Everything you need to know - BI connector Blog\" \/>\n<meta property=\"og:description\" content=\"Check out what's Query folding in Power BI, along with the steps to set up query folding for the list of data sources supporting the feature.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/\" \/>\n<meta property=\"og:site_name\" content=\"BI connector Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-21T14:13:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-18T05:16:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dev.biconnector.com\/blog\/wp-content\/uploads\/2023\/02\/Query-Folding-2-1-1536x804-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"804\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"BI Connector Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"BI Connector Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/\",\"url\":\"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/\",\"name\":\"Query Folding in Power BI: Everything you need to know - BI connector Blog\",\"isPartOf\":{\"@id\":\"https:\/\/dev.biconnector.com\/blog\/#website\"},\"datePublished\":\"2023-02-21T14:13:47+00:00\",\"dateModified\":\"2023-05-18T05:16:29+00:00\",\"author\":{\"@id\":\"https:\/\/dev.biconnector.com\/blog\/#\/schema\/person\/861351d5d0c055d8c0c6d5bde42836b9\"},\"description\":\"Check out what's Query folding in Power BI, along with the steps to set up query folding for the list of data sources supporting the feature.\",\"breadcrumb\":{\"@id\":\"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dev.biconnector.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Query Folding in Power BI: Everything you need to know\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dev.biconnector.com\/blog\/#website\",\"url\":\"https:\/\/dev.biconnector.com\/blog\/\",\"name\":\"BI connector Blog\",\"description\":\"Blog on BI, Analytics, and Integration\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dev.biconnector.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/dev.biconnector.com\/blog\/#\/schema\/person\/861351d5d0c055d8c0c6d5bde42836b9\",\"name\":\"BI Connector Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dev.biconnector.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7160ad63033671078ece993f850d16b3?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7160ad63033671078ece993f850d16b3?s=96&d=wavatar&r=g\",\"caption\":\"BI Connector Team\"},\"sameAs\":[\"https:\/\/www.biconnector.com\/\"],\"url\":\"https:\/\/dev.biconnector.com\/blog\/author\/bi-connector-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Query Folding in Power BI: Everything you need to know - BI connector Blog","description":"Check out what's Query folding in Power BI, along with the steps to set up query folding for the list of data sources supporting the feature.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Query Folding in Power BI: Everything you need to know - BI connector Blog","og_description":"Check out what's Query folding in Power BI, along with the steps to set up query folding for the list of data sources supporting the feature.","og_url":"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/","og_site_name":"BI connector Blog","article_published_time":"2023-02-21T14:13:47+00:00","article_modified_time":"2023-05-18T05:16:29+00:00","og_image":[{"width":1536,"height":804,"url":"https:\/\/dev.biconnector.com\/blog\/wp-content\/uploads\/2023\/02\/Query-Folding-2-1-1536x804-1.png","type":"image\/png"}],"author":"BI Connector Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"BI Connector Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/","url":"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/","name":"Query Folding in Power BI: Everything you need to know - BI connector Blog","isPartOf":{"@id":"https:\/\/dev.biconnector.com\/blog\/#website"},"datePublished":"2023-02-21T14:13:47+00:00","dateModified":"2023-05-18T05:16:29+00:00","author":{"@id":"https:\/\/dev.biconnector.com\/blog\/#\/schema\/person\/861351d5d0c055d8c0c6d5bde42836b9"},"description":"Check out what's Query folding in Power BI, along with the steps to set up query folding for the list of data sources supporting the feature.","breadcrumb":{"@id":"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dev.biconnector.com\/blog\/query-folding-power-bi-everything-you-need-to-know\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dev.biconnector.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Query Folding in Power BI: Everything you need to know"}]},{"@type":"WebSite","@id":"https:\/\/dev.biconnector.com\/blog\/#website","url":"https:\/\/dev.biconnector.com\/blog\/","name":"BI connector Blog","description":"Blog on BI, Analytics, and Integration","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dev.biconnector.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/dev.biconnector.com\/blog\/#\/schema\/person\/861351d5d0c055d8c0c6d5bde42836b9","name":"BI Connector Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dev.biconnector.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7160ad63033671078ece993f850d16b3?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7160ad63033671078ece993f850d16b3?s=96&d=wavatar&r=g","caption":"BI Connector Team"},"sameAs":["https:\/\/www.biconnector.com\/"],"url":"https:\/\/dev.biconnector.com\/blog\/author\/bi-connector-team\/"}]}},"_links":{"self":[{"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/posts\/4251"}],"collection":[{"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/comments?post=4251"}],"version-history":[{"count":1,"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/posts\/4251\/revisions"}],"predecessor-version":[{"id":4379,"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/posts\/4251\/revisions\/4379"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/media\/4378"}],"wp:attachment":[{"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/media?parent=4251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/categories?post=4251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.biconnector.com\/blog\/wp-json\/wp\/v2\/tags?post=4251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}