Sub topic 12
Aggregation Tables to Speed Up Large DirectQuery Models
This chapter assumes you know star schema, basic DAX, and the difference between Import and DirectQuery storage modes. It also assumes you have seen composite models and Dual tables in the previous chapter.
The problem aggregations solve
A DirectQuery fact table with billions of rows sends every visual's query to the source. Most visuals ask for totals by year, category, or region. Scanning the full table to answer them is slow and puts load on the source.
An aggregation table is a smaller, pre-summarized copy of a fact table. You load it in Import mode, so VertiPaq answers summary queries from memory. The detailed fact table stays in DirectQuery and is used only when a query needs detail the aggregation cannot supply.
How the engine chooses
When a query arrives, the engine checks whether the aggregation table can answer it. This depends on the columns the query groups by and the measures it uses. If it can, the engine reads the aggregation table. If not, it falls back to the DirectQuery detail table. Report authors and users do not choose. The same measure works either way.
Setting up an aggregation
- Create a summarized table at the grain you need, for example sales by date and product category. Build it in the source, or with a query in Power Query.
- Set the aggregation table to Import mode.
- Keep the detail table (for example
FactSales) in DirectQuery. - Set the dimension tables that relate to both to Dual. Dual tables can serve the Import aggregation or generate a query to the DirectQuery source, depending on the query.
- In Power BI Desktop, right-click the aggregation table and choose Manage aggregations. For each column, choose a summarization (Sum, Count, Min, Max, GroupBy, or Count table rows) and the detail table and column it maps to.
- The aggregation table is then hidden from report users.
A small table of mappings might look like this:
| Aggregation column | Summarization | Detail table | Detail column |
|---|---|---|---|
| SalesAmount | Sum | FactSales | SalesAmount |
| OrderCount | Count table rows | FactSales | (none) |
| DateKey | GroupBy | FactSales | DateKey |
| ProductKey | GroupBy | FactSales | ProductKey |
A measure such as SUM ( FactSales[SalesAmount] ) is then answered from the aggregation table whenever the query groups only by Date and Product attributes. A query that groups by FactSales[OrderNumber] falls back to the source.
Total Sales = SUM ( FactSales[SalesAmount] )Common errors
- The aggregation is never hit. The query groups by a column that is not mapped, or a relationship is missing. Check that every GroupBy column maps correctly and that dimensions are Dual.
- Wrong results. The aggregation grain does not match the detail data, or the table was refreshed on a different schedule from the source. Rebuild it after the source changes.
- Row-level security surprises. Aggregations work with RLS only when the security filter is applied on a dimension table related to both the aggregation and the detail table.
- Unsupported measures. Only Sum, Count, Min, Max, and row counts map directly. Measures like
DISTINCTCOUNTover detail columns usually fall back to the source unless the column is a GroupBy column.
Verifying it works
Open Performance Analyzer and look at the DirectQuery duration for a visual. If aggregation hits occur, the visual shows no DirectQuery time. SQL Server Profiler or DAX Studio can also show whether a query read the aggregation table.
Exercise
A DirectQuery FactSales table has an Import aggregation table grouped by DateKey and ProductKey. A visual groups sales by FactSales[OrderNumber]. Which table answers it, and why?
Show answer
The DirectQuery FactSales table answers it. OrderNumber is not a GroupBy column in the aggregation table, so the aggregation cannot supply that grain. The engine falls back to a SQL query against the source.