Close Menu
    Trending
    • Creating AI that matters | MIT News
    • Scaling Recommender Transformers to a Billion Parameters
    • Hidden Gems in NumPy: 7 Functions Every Data Scientist Should Know
    • Is RAG Dead? The Rise of Context Engineering and Semantic Layers for Agentic AI
    • ChatGPT Gets More Personal. Is Society Ready for It?
    • Why the Future Is Human + Machine
    • Why AI Is Widening the Gap Between Top Talent and Everyone Else
    • Implementing the Fourier Transform Numerically in Python: A Step-by-Step Guide
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » What Is a Query Folding in Power BI and Why should You Care?
    Artificial Intelligence

    What Is a Query Folding in Power BI and Why should You Care?

    ProfitlyAIBy ProfitlyAIJuly 25, 2025No Comments21 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    a question folding?” “Does your question fold?”… Possibly somebody requested you these questions, however you have been like: “Question…Whaaaat?!”

    Or, perhaps you’ve heard about question folding in Energy BI, however didn’t know tips on how to make the most of it in real-life eventualities.

    When you acknowledged your self in (at the very least) one of many two conditions specified above, then please proceed studying this text.

    Tremendous, you might be curious to seek out out what a Question folding is. However, first issues first…Earlier than you proceed, we have to set up some theoretical foundations, which is able to put the Question folding characteristic within the correct context.

    Knowledge Shaping

     and why it is one of the key concepts in the data preparation phase. Now, I would like to expand on that in a (maybe) unusual way:

    I guess you all know about the book written by Thomas More, called “Utopia”.

    In that story, everything is perfect and everyone is satisfied. In an ideal world, let’s call it “Data Utopia”, we have clean, high-quality data that just flies into our reports “as-is”, without needing to perform any kind of face-lifting or transformations along the way. Unfortunately, “Data Utopia” can exist only in books — the reality is crueler — as we have to deal with numerous challenges while nurturing our data.

    That being said, one of the key concepts that we have to absorb is Data Shaping. Data shaping is the process you should perform once you get familiar with your data, and become aware of possible pitfalls within the data you are planning to use in your business intelligence solution.

    I’ve intentionally used the term “Business Intelligence” instead of “Power BI”, as this is a general concept that should be used outside of Power BI solutions too.

    In simple words, data shaping is the process of data consolidation, BEFORE it becomes part of your data model. The key thing to keep in mind is the word: BEFORE! So, one would perform data shaping before the data goes into the report itself. Data shaping can be done at different places, and, depending on where you apply data shaping techniques, at different points in time during the data preparation process.

    WHERE should you perform data shaping?

    Source Database — This is the most obvious choice and in most cases the most desirable scenario. It is based on traditional data warehousing principles of Extracting-Transforming-Loading (ETL) data. In this scenario, you define what data you want to extract (not all data from the database is needed, and it’s usually not a good idea to import all the data). Then, you determine in case your knowledge must be remodeled alongside the way in which, to fit your reporting wants higher — for instance, do you need to carry out forex conversion, or do that you must conform nation and metropolis names?

    Do you acknowledge town within the following picture?

    Image by Lukas Kloeppel on Pexels

    Sure, it’s New York. Or, is it NYC? Or, is it New York Metropolis? Which one in all these three names is appropriate? Sure, all of them are appropriate — however should you import the info into your knowledge mannequin like this, you’re going to get incorrect outcomes — as every New York, NYC, and New York Metropolis shall be handled as a separate entity. This, and lots of extra potential caveats, should be solved in the course of the Knowledge Shaping part, and that’s why it’s vital to spend a while massaging your knowledge.

    Energy Question

    When you don’t carry out knowledge transformations on the supply aspect, the subsequent station is Energy Question — it’s the built-in software inside Energy BI, that enables you to perform all kinds of transformations to your data. In response to Microsoft’s official documentation, you’ll be able to apply greater than 300 completely different transformations!

    The important thing benefit of Energy Question is that you could carry out advanced knowledge transformations with little or no coding abilities! Moreover, all steps you’ve utilized in the course of the knowledge transformation course of are being saved, so each time you refresh your dataset, these steps shall be routinely utilized to form your knowledge and put together it for consumption by way of stories.

    Underneath the hood of Energy Question is a Mashup engine, that allows your knowledge shaping to run easily. Energy Question makes use of a really highly effective M language for knowledge manipulation. And, now you might be in all probability asking yourselves, what does all this story about knowledge shaping, Energy Question, Mashup engine, M language, and so forth. should do with Question folding? I don’t blame you, it’s a good query, however we’ll come again quickly to reply it.

    What’s a Question folding?

    For some knowledge sources, equivalent to relational databases, but additionally non-relational knowledge sources, for instance, OData, AD, or Alternate, the Mashup engine is ready to “translate” M language to a language that the underlying knowledge supply will “perceive” — normally, it’s SQL.

    Photo by Josh Sorenson on Pexels

    By pushing advanced calculations and transformations on to a supply, Energy Question leverages the capabilities of the sturdy relational database engines, which might be constructed to deal with giant volumes of knowledge in essentially the most environment friendly means.

    That skill of Energy Question’s Mashup engine to create a single SQL assertion combining all M statements behind your transformations is what we name Question folding.

    Or, let`s make it easy: if the Mashup engine is ready to generate a single SQL question that’s going to be executed on the info supply aspect, we are saying that the question folds.

    Knowledge sources that assist Question folding

    As already talked about, the obvious beneficiary of question folding is relational database sources, equivalent to SQL Server, Oracle, or MySQL. Nonetheless, it`s not simply that SQL databases make the most of the question folding idea. Primarily, any knowledge supply that helps some type of querying language can probably make the most of question folding. These different knowledge sources are OData, SSAS, SharePoint lists, Alternate, and Entra ID.

    Alternatively, if you use knowledge sources equivalent to Excel recordsdata, BLOB storage recordsdata, flat recordsdata, and so forth. in your Energy BI datasets, the question can’t fold.

    Knowledge Transformations that assist Question folding

    Nonetheless, on the subject of knowledge sources that assist question folding on the whole, it’s vital to remember the fact that not all transformations might be folded and pushed to a knowledge supply. So, simply to be clear, the truth that a SQL database helps question folding doesn’t essentially imply that your question will fold! There are some Energy Question transformations that merely can`t be pushed to a SQL database engine.

    Fairly often, some refined variations within the Energy Question transformations might be decisive within the closing consequence, and whether or not your question will fold or not. I’ll present you a number of of these refined variations within the following sections.

    Typically talking, the next transformations, when utilized in Energy Question, might be “translated” to a single SQL assertion:

    • Eradicating columns
    • Renaming columns
    • Filtering rows, with static values or Energy Question parameters, as they’re handled as WHERE clause predicates in SQL
    • Grouping and summarizing, that are equal to SQL’s Group by clause
    • Merging of foldable queries primarily based on the identical supply, as this operation might be translated to JOIN in SQL. Once I stated, merging of foldable queries — which means it should work in case you are becoming a member of two SQL server tables, but it surely won’t work in case you are making an attempt to affix a SQL desk and an Excel file
    • Appending foldable queries primarily based on the identical supply — this transformation pertains to the UNION ALL operator in SQL
    • Including customized columns with easy logic. What does easy logic imply? Utilizing M features which have equivalents in SQL language, for instance, mathematical features, or textual content manipulation features
    • Pivot and Unpivot transformations

    Alternatively, some transformations that can stop the question from folding are:

    • Merging queries primarily based on completely different sources, as defined beforehand
    • Appending (union-ing) queries primarily based on completely different sources — comparable logic as within the earlier case
    • Including customized columns with advanced logic or utilizing some M features that don’t have a counterpart in SQL
    • Including index columns
    • Altering a column knowledge sort. This one is a typical “it relies upon” case. I’ll present you quickly what it is determined by, however simply remember the fact that altering a column knowledge sort might be each a foldable and a non-foldable transformation

    Now, let’s study why you will need to obtain this habits — or, perhaps it’s higher to say, why do you have to care if the question folds or not?

    Why do you have to care about Question folding?

    If you’re utilizing Import mode in Energy BI, the info refresh course of will work extra effectively when the question folds, each when it comes to refresh velocity and useful resource consumption.

    In case you are working with DirectQuery or Twin storage mode, as you might be focusing on the SQL database instantly, all of your transformations MUST fold — or your resolution won’t work.

    Lastly, question folding can be of key significance for Incremental refresh — it’s so vital that Energy BI will warn you as soon as it determines that question folding can’t be achieved. It won’t break your incremental refresh “per-se”, however with out question folding in place, an incremental refresh wouldn’t serve its foremost goal — to scale back the quantity of knowledge that must be refreshed in your knowledge mannequin — as with out question folding, Mashup engine must retrieve all knowledge from the supply after which apply subsequent steps to filter the info.

    With all these in thoughts, you must have a tendency to realize question folding every time potential.

    Sluggish report — don’t blame Question folding!

    One vital disclaimer right here, and this is among the key takeaways from this collection of weblog posts: in case your report is gradual, or your visuals need a lot of time to render, or your data model size is large, question folding has nothing to do with it!

    Provided that your knowledge refresh or incremental refresh is gradual and inefficient, you must examine your Energy Question steps in additional depth.

    All or nothing?

    Just a few extra issues to remember relating to question folding. It’s not an all-or-nothing course of. Which means when you’ve got, let’s say, 10 transformation steps inside Energy Question, and your question folds till the sixth step, you’ll nonetheless get some profit from partial question folding. Nonetheless, as soon as the question folding is damaged, it may well’t be achieved anymore.

    Picture by writer

    To simplify, when you’ve got 10 transformation steps, and your question folding is damaged within the fifth step, all earlier steps will fold, however as soon as the folding is damaged, it may well’t be achieved once more, even when you’ve got transformations that assist question folding by default in steps 6 to 10 — like in our instance the place filtering must be a foldable step, these steps won’t fold. Hold that in thoughts, and attempt to push all non-foldable steps down the pipeline as a lot as potential.

    How have you learnt if the question folds?

    Okay, now we aren’t rookies anymore. We all know what question folding is, why we must always try to realize it, and a few refined tips that may make an enormous distinction.

    Now, it’s time to learn to verify if the particular question folds or not. The primary and most evident means is to right-click on the step and verify what the View Native Question possibility seems like.

    If it’s greyed out, this step in all probability doesn’t fold. Alternatively, if you’ll be able to click on on this selection, that implies that your question will fold. I suppose you might be perhaps confused with the phrase: PROBABLY!

    Picture by writer

    However, that’s the correct phrase, as you’ll be able to’t be 100% certain that if the View Native Question possibility is disabled, your question doesn’t fold. I’ll present you later how this selection can trick us into pondering that the question folding was damaged, despite the fact that, in actuality, folding truly happens.

    As an alternative, if you need to make sure in case your question folds or not, you need to use the Question Diagnostics characteristic inside Energy Question Editor, or SQL Server Profiler, like a superb previous and dependable technique to verify the queries despatched to a database by the Energy BI engine.

    Moreover, there’s a cool characteristic in Energy Question On-line, the place every step is marked with the icon that exhibits if that step folds, doesn’t fold, or is unknown. As I stated, this characteristic is offered solely in Energy Question On-line at this second, so let’s hope that the Energy BI group will implement it within the Desktop model quickly.

    Picture by writer

    The satan is within the particulars…

    Tremendous…You’ve in all probability heard in regards to the saying that the satan is within the particulars. Now, it’s time to know how little nuances could make an enormous distinction in our knowledge transformation course of.

    Let’s begin with one of the crucial curious circumstances in Energy Question editor…

    Satan #1 — Merge Be a part of

    This one may be very fascinating, as you’ll hardly assume what is occurring within the background. Let’s say that I need to mix two of my queries into one. I’ll use the Journey Works pattern database, and I have to merge the FactInternet Gross sales and DimCustomer tables.

    I’ll take away among the columns from my reality desk, and preserve solely the CustomerKey column, as this can be a international key to a DimCustomer desk, and the Gross sales Quantity column. I’ll be a part of the DimCustomer desk as it’s, with none extra steps earlier than merging.

    Picture by writer

    Merging tables is equal to JOIN operation in SQL. Primarily, we select the column on which we need to carry out MERGE operation, and the kind of be a part of (left, outer, or interior).

    Picture by writer

    The issue is that by default, if you’re merging two queries, Energy Question will generate a nested be a part of assertion, which might’t be correctly translated in SQL.

    Picture by writer

    If I’m going to the Instruments tab and click on on Diagnose Step, I can see that the Mashup engine fired two separate queries to my underlying SQL Server database — in different phrases, these two queries couldn’t be executed as a single SQL assertion, and that implies that question didn’t fold!

    Picture by writer

    How can we clear up this? Let’s simply select a clean question and write our M code by hand to realize precisely the identical outcome.

    Picture by writer

    The important thing factor is that we’ll use an identical, however nonetheless completely different M operate: Desk.Be a part of.

    We are actually utilizing Desk.Be a part of operate – Picture by writer

    All operate arguments are precisely the identical as beforehand, and let’s now verify the end result.

    You keep in mind as soon as I advised you that when the View Native Question is greyed out, your question in all probability doesn’t fold, but it surely’s not 100% appropriate. And, this can be a good instance. When you check out View Native Question, it nonetheless exhibits that our question doesn’t fold…

    Picture by writer

    …however let’s go to Diagnostics and verify if that’s true.

    Picture by writer

    Oh, boy, we have been tricked — this step certainly folded! As you’ll be able to see within the illustration above, we now have a single SQL question generated and despatched to a SQL Server supply database to be executed.

    So, we discovered two devils on this instance — the primary one was a be a part of sort, which we have been in a position to clear up by tweaking the routinely generated M code. And, the opposite one was the wrong habits of the View Native Question possibility. I’ll present you within the subsequent a part of the collection another instance when View Native Question lies.

    Question folding in Energy BI — tips, lies & final efficiency take a look at

    I assume you are actually acquainted with the idea of question folding in Energy BI, and particularly with its significance for knowledge refresh and incremental refresh processes. We’ve additionally began to scratch some fascinating behaviors of Energy Question transformations, and on this closing a part of the article, I’ll present you a number of extra fascinating findings.

    Lastly, we’ll wrap it up with the last word efficiency take a look at — I’ll present you the precise numbers behind two similar queries — one folds, and the opposite doesn’t!

    Altering Knowledge varieties

    One of the widespread transformations in Energy Question is altering knowledge sort. It’s a widely known best practice to use proper data types in your knowledge mannequin — for instance, should you don’t want hours, minutes, and seconds degree of granularity in your stories, try to be higher off eliminating them and altering the info sort of that column from Date/Time to Date solely.

    Nonetheless, the highway to hell is paved with good intentions:)…So, let me present you one refined distinction that may trigger your question to turn out to be rattling gradual, despite the fact that you’ve caught with the advice to make use of a correct knowledge sort!

    Picture by writer

    As you’ll be able to spot within the illustration above, my OrderDate column is of Date/Time knowledge sort. And, I need to change it to Date solely. There are (at the very least) two potential choices to do that — the primary one is to right-click on the column, develop the drop-down for the Change Sort possibility (like I did within the illustration), and choose Date sort (slightly below the Date/Time):

    Picture by writer

    Just a few vital issues occurred right here, so let me clarify every of these:

    1. Within the Utilized Steps pane, you’ll be able to discover that our transformation step had been recorded
    2. Within the column itself, you’ll be able to see that the time portion disappeared
    3. Once I’ve opened the View Native Question dialog field, you’ll be able to see that the Mashup engine properly translated our transformation to a T-SQL CONVERT() operate
    4. The M method utilized to this transformation step is: Desk.TransformColumnTypes()

    Let’s now study the opposite possibility to alter knowledge sort of our column:

    Picture by writer

    Slightly below our earlier Change Sort possibility, there’s a Remodel possibility. When you develop the drop-down, you’ll be able to see the Date Solely transformation. Let’s click on on it and verify what occurs:

    Picture by writer

    Seems to be fairly comparable, does it? However, let’s stroll by all of the issues that occurred now:

    1. As an alternative of the Modified Sort step, we now have a step referred to as Extracted Date
    2. The column itself seems precisely the identical as within the earlier instance — no time half in there
    3. Ooops, the question doesn’t fold anymore! As you’ll be able to see, the View Native Question possibility is greyed out!
    4. This time, M method utilized is: Desk.TransformColumns()

    So, one single completely different phrase within the M method (Desk.TransformColumnTypes vs Desk.TransformColumns) affected our question so exhausting that it couldn’t be translated to SQL!

    Takeover from this story: watch out, and be careful if you’re selecting choices for altering knowledge varieties!

    Liar, Liar…

    I’ve promised within the earlier a part of the article that I’ll present you another instance when the View Native Question possibility can idiot you into pondering that question folding was damaged, even when in actuality it’s not true…

    Let’s say that we need to preserve solely the highest X rows from our desk. In my case, I need to protect the highest 2000 rows from my reality desk:

    Picture by writer

    As soon as I’ve utilized this step and checked the View Native Question, I can understand that my question folds, as my transformation was translated to a TOP clause in SQL:

    Picture by writer

    Now, let’s say that I need to apply Absolute worth transformation on my Gross sales Quantity column. Usually, this transformation simply folds, as there’s an ABS operate in T-SQL:

    Picture by writer

    Nonetheless, if I right-click on this step, I’ll see that the View Native Question possibility is greyed out, so I’d assume that this step broke my question folding!

    Picture by writer

    Let’s verify this in our Question Diagnostics software:

    Picture by writer

    Oh, my God! This step folded certainly! So, we have been tricked by the View Native Question possibility once more!

    The important thing takeover right here is: everytime you’re assuming {that a} particular transformation step might be folded (like on this instance, once we knew that SQL has an ABS operate to assist our transformation), double-check what actually occurs beneath the hood!

    The final word efficiency take a look at

    Okay, if I didn’t handle to persuade you thus far, why you must try to realize question folding, let me now pull my final ace up my sleeve!

    I need to present you the distinction in knowledge refresh efficiency between the queries that return precisely the identical outcomes — one in all them folds, and the opposite doesn’t!

    Take a look at #1 Question folding ON

    For this testing, I’ll use the FactOnlineSales desk from the Contoso pattern database. This desk has round 12.6 million rows, and it’s good to display the magnitude of significance of the question folding idea.

    Within the first instance, I’ve utilized 9 completely different transformation steps, and all of them are foldable, as you’ll be able to see within the following illustration:

    Picture by writer

    Don’t take note of the SQL code that the Mashup engine generated: in case you are a SQL skilled, after all, you could possibly write far more optimum SQL code — nonetheless, remember the fact that with auto-generated scripts by the Mashup engine, you aren’t getting the most optimum SQL — you might be simply getting appropriate SQL!

    I’ll hit Shut & Apply and activate my stopwatch to measure how a lot time my knowledge refresh lasts.

    Picture by writer

    This question took 32 seconds to load 2.8 million information in my Energy BI report. Knowledge was loaded in batches of 100.000–150.000 information, which is an efficient indicator that the question folding is in place.

    Take a look at #2 Question folding OFF

    Now, I’ll return to Energy Question Editor, and deliberately break question folding on the third step (keep in mind the instance above with altering Date/Time sort to Date), utilizing the transformation for which I do know that isn’t foldable:

    Picture by writer

    Fact to be stated, I’ll obtain a partial folding right here, as first two steps will fold, however all subsequent steps after the Extracted Date transformation won’t fold!

    Let’s activate the stopwatch once more and verify what occurs:

    Picture by writer

    The very first thing to note: this question took 4 minutes and 41 seconds to load into our Energy BI report, which is roughly 10 instances extra than in our earlier case when the question folded. This time, batches of loaded knowledge have been between 10.000 and 20.000 information.

    However, what’s much more regarding — you’ll be able to see that the entire variety of information loaded was nearly 11 million!!! As an alternative of two.8 million within the earlier instance! Why is it taking place? Effectively, within the earlier sections, I defined that when the Mashup engine can’t translate M language to SQL, it wants to drag ALL the info (from the second when the question folding was damaged), and THEN apply transformations on the entire chunk of imported knowledge!

    The ultimate result’s precisely the identical — we now have 2.830.017 information in our Energy BI report — however, with question folding in place, all mandatory transformations have been carried out on the SQL database aspect, and the Mashup engine bought an already ready knowledge set. Whereas within the second situation, after we broke the question folding, the Mashup engine pulled the entire remaining rows (approx. 11 million), and solely after that was it in a position to apply different transformation steps.

    And, this was only a fundamental instance, with one single desk, and never so large when it comes to knowledge quantity! Merely think about the magnitude of implications on a bigger dataset, with a number of tables in it.

    Conclusion

    Effectively, we lined so much on this article. We realized in regards to the knowledge shaping idea, we launched Energy Question fundamentals, and we additionally realized what question folding is and why we must always do our greatest to realize it.

    I’ve additionally shared with you some fundamental examples and neat tips on tips on how to obtain question folding in some widespread use circumstances.

    Ultimately, please bear in mind that the question folding is a piece in progress, and people from the Energy BI group are always enhancing this characteristic. So, it may well occur that among the points with question folding I’ve proven you listed here are resolved within the meantime. Subsequently, make sure to keep updated with the newest enhancements.

    Thanks for studying!



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleDeclarative and Imperative Prompt Engineering for Generative AI
    Next Article Nothing lanserar en AI-smartklocka CMF Watch 3 Pro
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    Creating AI that matters | MIT News

    October 21, 2025
    Artificial Intelligence

    Scaling Recommender Transformers to a Billion Parameters

    October 21, 2025
    Artificial Intelligence

    Hidden Gems in NumPy: 7 Functions Every Data Scientist Should Know

    October 21, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Liberating Performance with Immutable DataFrames in Free-Threaded Python

    July 7, 2025

    Solving the generative AI app experience challenge

    April 5, 2025

    Första AI-genererade scenen på en Netflix serie

    July 21, 2025

    Forget ChatGPT? Alibaba’s Qwen3 Might Be the New AI King

    April 29, 2025

    7 ChatGPT Prompts For Business In 2025 » Ofemwire

    April 4, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    Moore’s Law • AI Parabellum

    April 3, 2025

    Meta släpper Llama 4 – AI nyheter

    April 6, 2025

    How a BPO hit SLAs for high-volume invoicing with automation

    April 4, 2025
    Our Picks

    Creating AI that matters | MIT News

    October 21, 2025

    Scaling Recommender Transformers to a Billion Parameters

    October 21, 2025

    Hidden Gems in NumPy: 7 Functions Every Data Scientist Should Know

    October 21, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.