Sub topic 3
How the VertiPaq Engine Stores and Compresses Data
This chapter assumes you can build a star schema in Power BI Desktop, write basic DAX measures, and know what fact and dimension tables are. You do not need to know anything about storage internals yet.
VertiPaq is the in-memory columnar engine that answers queries for Import tables and Direct Lake tables. Understanding how it stores data explains why Import models are fast, why model size depends on column cardinality more than row count, and why some modeling habits make a model large.
Why a columnar engine
A relational database such as SQL Server normally stores data in rows. All the values of one order sit next to each other on disk. That layout suits transactional work, such as reading or updating one order.
Report queries are different. A visual that shows total sales by year needs only two columns, the date and the amount. It reads millions of rows but ignores most of the table's columns. A row store must read through whole rows to find those two values.
VertiPaq stores each column separately. A query reads only the columns it references, and the values in one column share a data type and often repeat. Repeated, similar values compress well. That is the basis for both the speed and the small size.
| Property | Row store | Column store (VertiPaq) |
|---|---|---|
| Data laid out together | All values of one row | All values of one column |
| Good at | Reading or changing single rows | Scanning and aggregating many rows |
| Columns read by a query | Often the whole row | Only the referenced columns |
| Compression | Modest | High, especially for repeated values |
What happens when data is loaded
When a table is loaded, VertiPaq processes it one column at a time. It reads the values, picks an encoding, splits the column into segments, and compresses each segment.
Dictionary encoding
Most columns are dictionary encoded. VertiPaq builds a dictionary of the distinct values in the column and replaces each stored value with a small integer that points into the dictionary.
Take a Country column with 10 million rows but only 40 distinct countries. VertiPaq stores 40 strings once, then 10 million small integers. Each integer needs only 6 bits, because 6 bits can represent up to 64 values. The long strings are not repeated.
This is why the number of distinct values (the cardinality) of a column drives its size. A column with 40 distinct values over 10 million rows is tiny. A column with 10 million distinct values, such as a transaction GUID, needs a large dictionary and wide integers, so it compresses poorly.
Value encoding
For numeric columns, VertiPaq can instead use value encoding. It stores the numbers directly, after subtracting an offset or dividing by a common factor so that fewer bits are needed. For example, values between 1,000,000 and 1,000,200 can be stored as offsets from 1,000,000, which fit in 8 bits.
VertiPaq chooses the encoding itself, based on a sample of the data. You cannot set it in Power BI Desktop. Dictionary encoding is usually the better choice for columns with few distinct values, and value encoding for dense numeric ranges.
Run-length encoding
After encoding, VertiPaq applies run-length encoding (RLE) where it helps. RLE replaces a run of identical consecutive values with the value and a count. Ten thousand consecutive rows with Country = 7 become one entry meaning "7, repeated 10,000 times".
RLE works best when equal values are next to each other. VertiPaq reorders rows within a segment to create longer runs. It tries the columns with the lowest cardinality first, since they give the longest runs.
Segments
A table is split into segments of about one million rows each. A segment is compressed and scanned as a unit, and segments can be scanned in parallel across CPU cores. During a refresh, the engine processes data in segments, so a large table is built segment by segment.
The first segment of a table can be larger when the engine is working out the best encoding. Do not rely on exact segment sizes. They are an internal detail and can change between versions.
What else is stored in memory
Column data is the largest part, but not the only part.
- Relationships. For each relationship, VertiPaq builds an in-memory structure that maps rows in the many side to rows in the one side. Relationships on high-cardinality key columns cost more memory.
- Hierarchies. Each user hierarchy has a structure of its own. Auto date/time tables also add hidden tables and relationships to every date column in the model.
- Calculated columns. A calculated column is computed at refresh time and stored like any imported column, so it uses memory. A measure is computed at query time and stores nothing.
For these reasons, a calculated column is often the wrong place for logic that a measure, or the source query, can supply.
What makes a model large
Because of dictionary encoding and RLE, you can predict where size comes from.
- High-cardinality columns. GUIDs, timestamps with seconds or milliseconds, free-text comments, and unrounded decimals all produce large dictionaries.
- Unneeded columns. Every column that is loaded costs memory, even if no report uses it. Remove columns you do not need before they reach the model.
- Wide date-time values. A
DateTimecolumn with a time of day has up to 86,400 distinct values per day. Split it into a date column and a time column. Both have low cardinality, and the pair uses much less space than the combined value. - Text where a number would do. Long text keys are stored in dictionaries. Integer surrogate keys are smaller.
- Many calculated columns. Each is stored in full.
A common fix is to reduce the precision of a column that does not need it. Rounding a currency amount to two decimals, or a measurement to the precision you actually report, cuts the number of distinct values.
Inspecting a model
You can see column sizes with external tools. DAX Studio's VertiPaq Analyzer view reads the model's metadata and lists, for each table and column, the dictionary size, data size, and cardinality. The same information is available from the DMV (dynamic management view) query below, which you can run in DAX Studio against a connected model.
EVALUATE
SELECTCOLUMNS (
INFO.STORAGETABLECOLUMNS (),
"Table", [DIMENSION_NAME],
"Column", [ATTRIBUTE_NAME],
"Dictionary bytes", [DICTIONARY_SIZE]
)
ORDER BY [DICTIONARY_SIZE] DESCSort by dictionary size and look at the top rows. The columns at the top are usually the ones to remove, round, or split.
How VertiPaq answers a query
When a visual runs, Power BI sends a DAX query to the engine. The engine has two parts that work together.
- The formula engine parses the DAX, builds a query plan, and evaluates complex logic. It runs in a single thread.
- The storage engine (VertiPaq) scans compressed column data and returns results to the formula engine. It is multi-threaded, and each thread can scan a separate segment.
The storage engine is very fast at simple operations such as filtering, grouping, and summing a column. The formula engine is slower, because its work is single-threaded. A fast query pushes as much work as possible into storage engine scans. A slow query often has a large number of storage engine requests, or a large intermediate result that the formula engine must process row by row.
This is the same split you use later with Performance Analyzer and DAX Studio. Both show how much time a query spent in each engine.
The measure below runs entirely as VertiPaq scans over the Quantity and UnitPrice columns of the Sales table.
Total Sales = SUMX ( Sales, Sales[Quantity] * Sales[UnitPrice] )VertiPaq can evaluate the row-by-row multiplication inside a scan, so this is still a storage engine operation. A DAX query such as the following is what a visual generates for it.
EVALUATE
SUMMARIZECOLUMNS (
'Date'[Year],
"Total Sales", [Total Sales]
)
ORDER BY 'Date'[Year]Only three columns are touched: Date[Year], Sales[Quantity], and Sales[UnitPrice], plus the relationship that joins the two tables. The other columns in the model stay out of the scan.
Where VertiPaq is used
The engine is the same, but the way data gets into it differs by storage mode.
| Storage mode | How data reaches VertiPaq | Who pays for the encoding work |
|---|---|---|
| Import | Copied from the source during refresh, then encoded and compressed | The refresh operation |
| Direct Lake | Column data is read from Delta files in OneLake and loaded into memory on demand | The first queries that need each column |
| DirectQuery | Not used for that table. Queries go to the source | The source system |
Import tables are compressed during refresh, so refresh time includes encoding. Direct Lake tables read Parquet files that are already column-oriented, and the engine loads them into its in-memory format when queries need them. Later chapters cover both modes in detail.
Common mistakes
- Treating row count as the only size driver. Ten million rows of low-cardinality data can be smaller than one million rows with a unique text value per row.
- Leaving the GUID or row ID column in the model. If no relationship or report uses it, remove it.
- Using calculated columns for arithmetic that a measure could do. The column is stored. The measure is not.
- Keeping auto date/time on a large model. It creates a hidden date table for every date column. Use one shared date table instead.
- Judging size by file size alone. A
.pbixfile is compressed on disk. Memory use at query time can be higher, because of temporary structures during queries and refresh.
Exercise
A fact table has 20 million rows. It has an OrderTimestamp column, recorded to the second, and a unique TransactionGuid column. Reports only analyze sales by day and never use the GUID. Name two changes that reduce the model's memory, and say why each works.
Show answer
First, remove TransactionGuid. Every value is distinct, so the dictionary is as large as the column and compresses poorly, and no report needs it. Second, split OrderTimestamp into a date column, or keep only the date. A timestamp to the second has a very high number of distinct values, while a date has only a few thousand. The smaller dictionary and narrower integers cut memory and give run-length encoding more repeated values to work with.
Exercise
Why does a calculated column increase model size while a measure with the same arithmetic does not?
Show answer
A calculated column is evaluated at refresh time and its results are stored and compressed like any other column, so it occupies memory. A measure is evaluated at query time, when a visual asks for it, and nothing is stored.