MSBA-261 · Lesson 11 of 12 · 21 min
Model performance
▶ Video coming soon A video version of this lesson is on the way.
Two weeks after the model went to the deans, Kwabena got the message every Power BI developer eventually receives. The Ridgeview coordinator wrote that the Weekly Outlets page took "about twenty seconds" to load, and the deans' overview was "a bit sluggish". The model file had also grown to 1.4 GB, close to the 1 GB limit that a Pro workspace places on a model in the service, which the institutional research team had only avoided because Lumenvale's Fabric capacity allowed larger models. This lesson covers how the Power BI engine stores data, how to make models smaller, and how to find and fix slow measures, relationships and visuals, the third skill area of the PL-300 modeling domain.
How imported data is stored
In Import mode, Power BI loads data into the VertiPaq engine, an in-memory columnar database. Each column is stored separately and compressed. Compression works by building a dictionary of a column's distinct values and storing each row as a small number pointing into the dictionary, then compressing runs of repeated values. The consequence that matters for design is simple: a column's size depends mostly on its cardinality, the number of distinct values, not the number of rows.
A column with nine distinct outlets compresses to almost nothing, however many rows it has. A timestamp precise to the second, a receipt number unique on every row, or a free-text comment can each be larger than the rest of the table combined. Kwabena's model analysis showed exactly that: the Sale Timestamp column alone was almost a third of the file.
Removing unnecessary rows and columns
The PL-300 study guide's first performance skill is to improve performance by identifying and removing unnecessary rows and columns. It is also the most effective single technique.
- Columns. Kwabena reviewed every column with a simple question: does any report or measure use it? Columns copied from the source "just in case", such as the cashier's terminal ID, the source system's row-modified time and two unused address lines, were removed in Power Query. Removing a column the model does not need is free performance.
- Rows. The outlet files went back to 2015, but no report looked before fiscal 2021. He filtered the history to the last six fiscal years in Power Query, which removed more than forty percent of the rows. The registrar kept older enrollment for long-term trend reports, so those rows stayed.
- Precision. He split Sale Timestamp into a date, used for the relationship, and an hour of day, used by the staffing report, and removed the timestamp. Two low-cardinality columns replaced one huge one. He also rounded money columns to two decimal places and set them to fixed decimal, which stores them efficiently.
- Text keys. Where a relationship used a long text code, he replaced it with an integer key.
Reducing granularity
The second skill is reducing granularity. A fact table stored at a finer grain than any report needs pays for detail nobody uses. The bookstore reports never looked at individual receipt lines older than a year; they looked at daily sales by outlet and category. Kwabena changed the design to two tables: a detailed Outlet Sales table for the current and previous fiscal year, and an Outlet Sales Daily summary table grouped by date, outlet and category for earlier years. A measure combined them.
Aggregating in the source or in Power Query, before the data reaches the model, is the most common way to reduce granularity. Power BI also supports aggregation tables, which let a model keep a small summary table in Import mode alongside a large detailed table in DirectQuery, with the engine choosing the summary when a query allows it. Those are mostly used for very large datasets and are beyond what Lumenvale needed.
Other model-size settings
- Auto date/time off, as discussed earlier, removes a hidden date table for every date column.
- Calculated columns that could be computed upstream, in Power Query or the source, often compress better there, because Power Query columns are compressed with the rest of the table's sort order in mind.
- Disable load on helper queries in Power Query so staging queries do not become model tables.
- Incremental refresh does not make the model smaller, but it makes refresh faster and more reliable by refreshing only recent partitions, which is covered in the course on deploying and maintaining Power BI assets.
After the changes, the model dropped from 1.4 GB to 380 MB and its refresh time fell from forty minutes to eleven.
Finding slow visuals with Performance Analyzer
Size is one problem; slow pages are another. Performance Analyzer, on the Optimize ribbon of Power BI Desktop, records how long each visual takes when you refresh a page. For each visual it splits the time into three parts: DAX query, the time the engine took to answer; visual display, the time to draw the result; and other, waiting for other visuals or background work.
| What Performance Analyzer shows | Likely cause | What to try |
|---|---|---|
| Long DAX query time | An expensive measure, a large table scan, or a slow relationship | Copy the query to DAX query view and rewrite the measure |
| Long visual display time | Too many data points or a heavy custom visual | Reduce points, use a built-in visual, or summarize |
| Long other time | Many visuals on the page competing | Reduce the number of visuals or combine them |
| Many visuals each a little slow | A crowded page | Split the page, use drill-through, or use a matrix instead of many cards |
The Weekly Outlets page had twenty-two visuals, including fourteen separate cards. Performance Analyzer showed that each card's query was quick, but together they queued. Replacing the cards with two multi-row card or matrix visuals cut the page load time by more than half before any DAX was changed.
Finding slow measures with DAX query view
For visuals with a long DAX query time, Performance Analyzer can copy the query. Pasted into DAX query view, the query can be run on its own, changed and run again, and Desktop shows how long it took. The PL-300 study guide names both tools: identify poorly performing measures, relationships and visuals using Performance Analyzer and DAX query view.
The slow measure on the Weekly Outlets page was an early version of average weekly margin.
// Slow: iterates every sales line and triggers context transition for each
Avg Weekly Margin (slow) =
AVERAGEX (
'Outlet Sales',
CALCULATE ( [Gross Margin], ALLEXCEPT ( 'Outlet Sales', 'Date'[Week Start] ) )
)
// Faster: iterate the distinct weeks, not the sales lines
Avg Weekly Margin =
AVERAGEX ( VALUES ( 'Date'[Week Start] ), [Gross Margin] )The first version iterated the whole fact table, calling a measure for each row. The second iterates the distinct weeks in context. Both return the same number; the second took a fraction of the time. Most slow DAX comes from a few patterns: iterating a large fact table when a small dimension would do, filtering whole tables instead of columns in CALCULATE, measures that are recalculated several times instead of stored in variables, and IF expressions that force both branches to be evaluated.
Slow relationships
Relationships can be slow too. Bidirectional relationships, many-to-many relationships, relationships on high-cardinality text columns, and long snowflake chains all add work to every query that crosses them. Kwabena's model was mostly a clean star, but one relationship joined Outlet Sales to Outlet on a text outlet name. Replacing it with an integer key and setting single direction gave a noticeable improvement on every outlet page.
Other tools
Beyond the two tools the study guide names, modelers commonly use:
- Best Practice Analyzer rules, available in tools such as Tabular Editor, and in Fabric through notebooks, which flag common problems such as bidirectional relationships, unused columns, floating-point money and missing descriptions.
- Model analysis tools that report each column's size and cardinality, which is how Kwabena found the timestamp problem.
- Query diagnostics in Power Query, for slow refreshes rather than slow visuals.
- Copilot in Desktop, which can explain a DAX query or suggest a rewrite; its suggestions, like any generated code, must be tested.
Storage modes and performance
Import mode is usually the fastest for queries because data sits in memory. DirectQuery sends each query to the source, so its speed depends on the source; it suits very large or near-real-time data. Direct Lake, available for models on Fabric capacity, reads data from Delta tables in OneLake into memory on demand, aiming to combine Import-like speed with data that does not need a scheduled import. Dual mode lets a dimension behave as Import or DirectQuery depending on the query. Lumenvale's enrollment model stayed in Import mode; storage mode choices are covered in more depth in the Power Query and deployment courses.
Worked problem
Planning a performance fix
A page with a matrix of programs by week loads in fifteen seconds. Performance Analyzer shows the matrix's DAX query takes thirteen seconds. The matrix uses a measure that ranks programs with RANKX over ALL ( Registration ). What should Kwabena do?
Show solution
- The time is in the DAX query, so look at the measure, not the visual.
- RANKX over ALL ( Registration ) iterates the whole fact table for every cell, evaluating a measure each time.
- Rank over the program dimension instead: RANKX ( ALLSELECTED ( Program[Program Name] ), [Registrations] ).
- Copy the query into DAX query view, run both versions and compare timings and results before publishing.
Answer: Rewrite the ranking to iterate the small Program dimension, then verify the speed and results in DAX query view.
A performance checklist before publishing
After the November clean-up, Rupert asked Kwabena to turn what he had learned into a checklist that every new model at Lumenvale would pass before going into production. It became a one-page document stored beside the model in the repository.
| Check | How | Pass when |
|---|---|---|
| Unused columns removed | Model analysis tool or a review of the Data pane | Every column is used by a measure, relationship, visual or documented need |
| High-cardinality columns justified | Column sizes in a model analysis | No unused timestamp, free text or unique ID columns |
| Auto date/time off | File options | Only the marked date table provides dates |
| Relationships single direction | Model view | Any bidirectional relationship is documented |
| Integer keys | Model view | Large relationships use whole-number columns |
| Pages load quickly | Performance Analyzer | Every page loads in a few seconds as a role member |
| Slow measures reviewed | DAX query view timings | No measure iterates a large fact table needlessly |
The checklist was deliberately short. Kwabena found that long checklists were skipped, while seven checks that took half an hour caught nearly every problem the college had seen.
Worked problem
Reading a model analysis
A model analysis of the facilities model shows that a column called Inspection Notes, free text written by inspectors, uses 60 percent of the model's memory. No visual uses it except one detail table that facilities staff open a few times a month. What should Kwabena recommend?
Show solution
- Free text has very high cardinality, which is why it is so large.
- Most readers never need it, so remove it from the main model.
- For the occasional detail need, link from the report to the inspection record in the facilities app, or use a drill-through to a paginated report that queries the source directly.
- Re-run the analysis and Performance Analyzer to confirm the model is smaller and pages faster.
Answer: Remove the notes column from the model and give the few users who need it a link or a paginated detail report that reads the source.
Measuring before and after
Every change Kwabena made was measured twice: once before and once after. He recorded the model size, the refresh time and the load time of the three slowest pages in a short table in the model's documentation. That habit mattered for two reasons. It showed which changes were worth the effort, since removing the timestamp column saved far more than any DAX change. And it gave Rupert evidence when he asked the deans to accept small compromises, such as keeping only six years of receipt-level detail.
Common mistakes
MistakeImporting every column from the source in case someone needs it.
InsteadRemove columns no report or measure uses; they can be added later if needed.
MistakeKeeping timestamps precise to the second when reports use dates and hours.
InsteadSplit into lower-cardinality date and hour columns and remove the timestamp.
MistakeTuning DAX before checking where the time goes.
InsteadUse Performance Analyzer first to see whether the time is in the query, the display or other visuals.
MistakePutting many single-value cards on one page.
InsteadCombine values into fewer visuals so queries do not queue.
Summary and key terms
- Imported data is stored in the VertiPaq columnar engine; column size depends mostly on cardinality.
- Removing unnecessary columns and rows is the most effective way to shrink a model.
- Reduce precision and granularity: split timestamps, use integer keys, and summarize old detail.
- Performance Analyzer splits visual time into DAX query, visual display and other.
- Copy slow queries into DAX query view to test and compare measure rewrites.
- Slow DAX often comes from iterating large tables, filtering whole tables and repeating calculations.
- Bidirectional, many-to-many and text-keyed relationships add query cost.
- VertiPaq
- The in-memory columnar engine that stores imported Power BI data.
- Cardinality (of a column)
- The number of distinct values in a column, which largely determines its size.
- Performance Analyzer
- A Power BI Desktop tool that records how long each visual takes to load.
- DAX query view
- A Desktop view for writing, running and timing DAX queries against the model.
- Granularity
- The level of detail at which data is stored.
- Direct Lake
- A storage mode for Fabric that reads Delta tables from OneLake into memory on demand.
- Best Practice Analyzer
- A set of rules, run in external tools, that flags common model design problems.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why does splitting a timestamp into a date and an hour make a model smaller?
Show answer
Each new column has far fewer distinct values, and size depends mostly on cardinality.
Performance Analyzer shows a long visual display time. What should you look at?
Show answer
The visual: too many data points or a heavy custom visual, rather than the DAX.
Name two tools the PL-300 study guide lists for finding poorly performing measures.
Show answer
Performance Analyzer and DAX query view.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.