Fabric Apps and Performance Optimization
Part 2: Query Rewrites
- Fabric Apps
- Power BI
- DAX
- Performance
In Part 1 of the series, we took a deeper look at optimizing the performance of Fabric Apps by reducing the number of queries used to populate the data in the app. For the next step in exploring the design factors driving the performance envelope of Fabric Apps, we are going to look at how the DAX queries themselves are written.
Just like in Part 1, where Power BI Reports traditionally had a fixed relationship between the number of visuals and the number of queries, there is also a fixed form that each query takes. But in a Fabric App, because each query is written in or generated by app code you control, you can customize the form of the query. In this post we’ll take a closer look at the impact changing that form can have.
Isolating what’s new
Tuning DAX to improve report performance is nothing new. Historically, though, we were always restricted to what goes in the model: the measure definitions and the model structure. In between the dashboard1 and the semantic model has always been a DAX query that returns a table to the report. To isolate that query layer, we will not look at the model design or measure logic at all in this post. I’m sure the measures Copilot generated for our sample model leave something to be desired. In our next post, we will take a closer look at whether we should change our measure logic around some of the new capabilities in Fabric Apps.
Generating Examples
Like in Part 1, I used examples generated by GitHub Copilot. I used the SpaceParts sample dataset (created by Tabular Editor ApS) instead of AdventureWorks for these examples; the DAX queries, custom measures, and Fabric App used here are available on GitHub. I once again had Copilot optimize the DAX in the apps it created to generate a series of examples to look at. We’ll take a closer look at the prompts I used to do that later in the post. Very briefly, across the two optimization sessions, the agents used 18.16 million tokens, or 977.44 GitHub Copilot AI Credits ($9.77 at list prices), and took 31 min 47 sec across the two run windows.
Trend Data Query
Based on the exploration the agent did, we decided to focus this blog post on a single query used by our SpaceParts app that powers the main bar and line combo chart.
What Changed Under the Hood
The change to the query is quite subtle. We have the same output schema in all of our examples. We have the same granularity and measures. But moving from a pure SUMMARIZECOLUMNS query to a SUMMARIZECOLUMNS + ADDCOLUMNS query we get 25% less storage engine CPU time. And then a further 40% reduction by changing how the query handles the date axis: generating the 24 month keys directly instead of range-filtering the date table, grouping the four measures by Month Start alone, and joining the Year Month display label back at the end. That adds one tiny scan (12 → 13), but lets the seven fact-table scans drop Year Month completely. Generating the month keys is a bit of an assumption, though a reasonable one in my opinion unless you’re working with a non-standard calendar. I would also add that I’ve always felt that ADDCOLUMNS queries are materially less readable than other patterns. But I guess that’s the agent’s problem now.
All timings below are cold semantic model query runs from workspace monitoring, not end-to-end app render time. Comparing observed cold-run medians from the original query to Round 2, elapsed time was 50% lower (656 → 328 ms) and total CPU was 56% lower (4,047 → 1,797 ms).
I’m honestly blown away by the magnitude of improvement here. I was expecting this type of optimization to have a barely measurable impact. I’m looking forward to exploring this space more and understanding why this form works so much better. But for the purpose of this blog post, the point is that you shouldn’t ignore this area. Especially considering we started in a pretty reasonable place. I don’t know how lucky we got there, but those first-pass, agent-generated queries could be MUCH MUCH worse, especially if you want to get away with a cheaper model. And maybe there was a big mess that got swept into my measure definitions. You shouldn’t ignore those. I only set them aside because that’s not new due to Fabric Apps. Measure definitions are just as important as they’ve always been.
At the same time, you don’t have to get into the weeds of the DAX your agent writes. Just ask it to spend some time trying things out.
Experimentation Trajectory
I had Copilot work on this DAX optimization experiment in two phases. In phase 1, I asked it to just try things, focusing on table optimizations. Then in phase 2, I asked it to use data and storage engine traces to make a more informed search for possibilities. I’d say the phase 1 prompt is well within the ability and context of most budding data engineers, citizen developers, or whatever we call them now. The phase 2 prompt does require some prior context with DAX optimization.
Once again, I did not install any custom skills or tools for my agents to give it any guidance on DAX best practices. Maybe you should, but I was curious how the agents would do out of the box. A lot of the skills out there were written in the GPT-5 era and can be highly prescriptive and conservative. The GPT-6 era models are just much much better (subjectively). I’ve been moving to a much more stripped-down skill setup almost across the board. But that’s another blog.
I had Copilot compile the performance of each experiment it ran through this process.
Finally, here are the lightly edited (for brevity and to remove off-topic discussions) verbatim prompts I used.
Starting the series:
Have an Opus 5.5 session design a sample business performance report for each [Adventure Works and Space Parts] dataset. then have Sol 6.1 implement those sample reports as both a pbi report and a fabric app. Use another opus session to review the examples against each other. then we can work through exploring these [performance optimization] changes one by one using the fabric app.
(As noted in Part 1, the only follow-up during design was a reminder to look at the Space Parts data before designing.)
Preparing for post 2:
[…] The first thing I want to do is move any logic in the base queries that should be in model measures into the model: we want to focus on the types of optimization that are NEW not just rehash measure optimization. from there, ideally we have a simple set of queries that generate tables from a set of dimensions and measures and filters. once we have that, we can ask a dedicated optimization session to explore query optimizations focusing on the ways the tables are generated and techniques around that. […]
Then I kicked off the baseline prep:
I want to use space parts this time. we can start with the query count the baseline one shot app has. have a sol 6.2 session get to work on the work to move reusable business logic into the model for our baseline.
Measure logic moved into the model; cold-cache baseline collected
ok with that baseline, have a fresh 6.2 high session begin testing alternative strategies. give it a 1 hour time limit and allow it to create subagents to explore different ideas. I especially want it to explore different uses of the table functions, Table manipulation - DAX Guide, and approches like TOJSON - DAX Guide to stack multiple result sets together. I also want to be sure that it tries the standard form that Power BI reports generate (it can see examples in the performance analyzer exports we have from the last blog work).
19 minutes later: Round 1 finds a faster trend query; Power BI style doesn't beat the baseline
great. we can focus on the one query you recommend. let’s do one more optimization. this time I want to give the optimization session the tools to use the query plan and execution data. […] in the workspace monitoring logs, there will be rows under VertiPaqSEQueryBegin for each storage event query with the XMSQL for that storage engine read in the event text field and the number of SE reads is a helpful metric to track when optimizing dax as well. lower is better. also the ratio of SE CPU to total CPU is helpful (other CPU is formula engine CPU). the SE is multi threaded. the FE is single threaded. so an ideal query has more work done in the SE in fewer seperate scans.
13 minutes later: Round 2 cuts runtime and CPU again on the same trend query
Conclusion
Power BI’s out-of-the-box query pattern is safe, flexible, and readable. But it’s not always the fastest way to fetch data from the semantic model. With Fabric Apps, we have the freedom to explore other patterns. That also means we have the freedom to let the agent mess this up. While in this blog post we looked at a very simple example, comparing observed cold-run medians from the original query to Round 2 still showed 50% lower elapsed time (656 → 328 ms) and 56% lower total CPU (4,047 → 1,797 ms) by applying a little bit of agent power to optimization.
What’s Next?
So far, we are assuming that, like Power BI, the data points returned by the query are the data shown on the page. But in Fabric Apps, that doesn’t have to be the case. You are not restricted to just DAX. You can implement any calculations or manipulations you want in the app code instead. In Part 3 of this series we will take a closer look at the many pitfalls and opportunities that creates.
-
I’m using dashboard generically here, to refer to both Power BI Reports, Fabric Apps, and similar BI front ends across vendors. The less said about Power BI Dashboards the better. ↩