
User-Defined Aggregations in Power BI
Speed up Power BI DirectQuery reports with user-defined aggregations. Pre-aggregate summary tables for sub-second query performance on billions of rows.
User-defined aggregations are Power BI's solution for the billion-row performance problem. When your fact tables contain hundreds of millions or billions of rows in a DirectQuery source, every dashboard interaction triggers a live query to the source database—and those queries can take 10-30 seconds or more, making reports unusable. Aggregations solve this by maintaining pre-computed summary tables in Import mode (in-memory) while keeping the full detail table in DirectQuery. Power BI's query engine automatically routes summary-level queries to the fast in-memory aggregation table and detail-level queries (drillthrough, individual transactions) to the DirectQuery source. Users experience sub-second performance for 90%+ of their interactions with seamless fallback to full detail when needed.
How the Aggregation Engine Works
Query Routing Logic
When a user interacts with a visual, Power BI's aggregation engine evaluates whether the query can be satisfied by an aggregation table:
- Check columns requested: Are all the group-by columns present in an aggregation table?
- Check aggregation functions: Does the aggregation table have the correct pre-computed function (SUM, COUNT, MIN, MAX) for the requested measure?
- Check filters: Can all applied filters be resolved against the aggregation table's columns?
- Route decision: If all conditions are met, route to the in-memory aggregation table (fast). If any condition fails, route to the DirectQuery detail table (slower but complete).
This routing is completely transparent to report users. They see the same visuals, apply the same filters, and get the same correct results—the only difference is speed.
Aggregation Priority
When multiple aggregation tables exist (different granularity levels), Power BI uses precedence to select the most efficient table:
| Aggregation Level | Granularity | Typical Size | Query Speed | |---|---|---|---| | Monthly summary | Month × Category × Region | Thousands of rows | Fastest (<100ms) | | Daily summary | Day × Product × Region | Millions of rows | Fast (<500ms) | | Detail (DirectQuery) | Individual transactions | Billions of rows | Slowest (5-30 seconds) |
Power BI selects the highest-precedence (most aggregated) table that can satisfy the query. Monthly visuals use the monthly table; daily trend charts use the daily table; individual transaction drills fall through to DirectQuery.
Setting Up Aggregations Step by Step
Step 1: Identify Aggregation Candidates
Analyze your report usage to determine which dimensions and measures are queried most frequently at summary levels. Use Performance Analyzer to identify:
- Which visuals generate the slowest queries
- Which group-by columns appear most frequently (Date at month level, Region, Product Category)
- Which aggregation functions are used (SUM of Revenue, COUNT of Orders, AVG of Price)
Step 2: Create the Aggregation Table
Build a summary table in your data source with pre-computed aggregations:
- Group-by columns: Date (at month or day level), dimension keys (Product Category, Region, Customer Segment)
- Aggregated measures: SUM(Revenue), SUM(Cost), COUNT(OrderID), MIN(OrderDate), MAX(OrderDate)
- Key mapping: Include dimension keys that map to the same dimension tables used by the detail table
The aggregation table should have dramatically fewer rows than the detail table—typically 1,000x to 100,000x fewer. If the aggregation table is not significantly smaller, the performance benefit is minimal.
Step 3: Import the Aggregation Table
Add the aggregation table to your model using Import storage mode. This loads the pre-computed summaries into VertiPaq memory for sub-second query performance. The detail fact table remains in DirectQuery mode—this is the composite model pattern.
Step 4: Configure Aggregation Mappings
In Power BI Desktop Model view, right-click the aggregation table and select "Manage aggregations." For each column in the aggregation table, configure:
- Summarization function: Match the pre-computed aggregation (Sum, Count, Min, Max, CountDistinct, GroupBy)
- Detail table: Select the detail DirectQuery table this aggregation summarizes
- Detail column: Map each aggregation column to its corresponding detail column
GroupBy columns (dimensions used for grouping) map to the same dimension columns that the detail table uses. This ensures Power BI can determine when a query's grouping level matches the aggregation table.
Step 5: Hide and Validate
Hide the aggregation table from report view. Users should never interact with it directly—they interact with the detail table and dimensions while Power BI silently routes queries to the aggregation table when possible.
Validate with Performance Analyzer: 1. Open a report, enable Performance Analyzer (View > Performance Analyzer) 2. Clear the cache (Performance Analyzer > Refresh) 3. Interact with visuals and inspect the query log 4. Queries served by the aggregation table show "Import" in the storage mode 5. Queries falling through to DirectQuery show "DirectQuery"
If queries that should use aggregations are falling through to DirectQuery, review your aggregation mappings for missing columns or incorrect summarization functions.
Advanced Patterns
Cascading Aggregations
For maximum performance across different detail levels, create multiple aggregation tables at different granularities:
- Monthly aggregation: Serves dashboard-level KPI cards and monthly trend charts
- Daily aggregation: Serves daily trend analysis and weekly comparisons
- Detail DirectQuery: Serves individual transaction views and ad-hoc exploration
Set precedence (in Manage Aggregations dialog) so monthly is checked first, then daily, then detail. Power BI uses the highest-precedence table that can satisfy each query.
Aggregations with Composite Models
Aggregations are most powerful in composite models where: - Dimension tables use Import mode (shared across aggregation and detail) - Aggregation fact table uses Import mode (fast in-memory) - Detail fact table uses DirectQuery (live data, no size limit)
This hybrid architecture gives you import-speed dashboards with real-time detail access, all within a single Power BI report.
Automatic Aggregations (Premium)
Power BI Premium and Fabric offer automatic aggregations that eliminate manual setup:
- Power BI analyzes query patterns over time
- Automatically creates and maintains in-memory aggregations for frequently queried data
- No manual table creation, mapping, or maintenance required
- Works best when query patterns are consistent and predictable
Automatic aggregations are ideal for organizations that want aggregation benefits without the data engineering effort. Manual aggregations remain necessary when you need precise control over granularity, inclusion of specific dimensions, or optimization for known query patterns.
Monitoring and Maintenance
Aggregation Hit Ratio
Track what percentage of queries are served by aggregation tables vs DirectQuery:
- Target: 80%+ of dashboard queries served by aggregations
- Monitor with: Performance Analyzer, Power BI Premium metrics, or DAX Studio with Server Timings
- Low hit ratio causes: Queries filtering on dimensions not included in the aggregation table, or requesting granularity below the aggregation level
Keeping Aggregations Current
Aggregation tables (Import mode) require scheduled refresh to stay current. Coordinate the aggregation refresh with the source data update schedule. Stale aggregation data produces incorrect results for summary visuals while detail drill-through shows current data—this inconsistency confuses users.
When Aggregations Are Not Enough
If even aggregation tables cannot deliver acceptable performance (very complex DAX, many concurrent users), consider:
- Migrating to Microsoft Fabric with Direct Lake mode (eliminates the need for manual aggregations)
- Moving the data source to a higher-performance database engine
- Redesigning the data model to reduce query complexity
Related Resources
Frequently Asked Questions
Are aggregations automatic or manual in Power BI?
Both options exist. You can manually create aggregation tables and configure mappings, or use automatic aggregations (Premium feature) that Power BI manages based on usage patterns.
Do aggregations work with all data sources?
Aggregations are most valuable for DirectQuery sources. For Import mode, the data is already in memory, so aggregations provide less benefit unless using composite models.