Composite Models

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Module: Implement Semantic Models

Lesson: Composite Models in Power BI

Introduction: The Evolution of Data Modeling

In the landscape of modern business intelligence, the ability to integrate disparate data sources into a single, cohesive view is the hallmark of an effective data architecture. Historically, data modelers were forced to choose between two rigid paths: Import mode, where data is physically copied into the model for high performance, or DirectQuery, where the model connects live to the source for real-time reporting. Each approach had significant limitations. Import mode could struggle with massive datasets that exceed memory limits, while DirectQuery often suffered from slow performance and limited transformation capabilities.

Composite models represent a transformative shift in this paradigm. They allow you to combine multiple DirectQuery data sources, or a mix of DirectQuery sources and imported data, within a single Power BI file. This flexibility enables organizations to build "hybrid" models that leverage the speed of cached data for frequently used metrics while maintaining a live connection to vast, petabyte-scale data warehouses for detailed, granular analysis. Understanding how to design and build these models is essential for any data professional looking to bridge the gap between agility and scale.


Not read yet

Understanding the Architecture of Composite Models

At its core, a composite model is a Power BI dataset that contains more than one source group. In a traditional import-only model, all tables belong to a single source group. When you introduce a second data source using DirectQuery, Power BI creates a new "source group." The data model then manages the relationships and query generation across these distinct groups.

When a user interacts with a report built on a composite model, the Power BI engine intelligently decides how to route the request. If the user filters a visual using data that is cached locally (Import mode), the engine retrieves it from the local memory. If the user then adds a measure that requires data from a remote SQL database, the engine generates a SQL query, sends it to the source, retrieves the result, and merges the results in the engine. This process happens behind the scenes, providing a unified experience for the end-user.

Callout: The "Source Group" Concept A source group is a logical boundary that defines how data is retrieved and processed. When you mix Import and DirectQuery, you are essentially telling the Power BI engine to treat these data sources as separate entities that must be joined at runtime. Understanding this boundary is critical because it dictates where your DAX calculations are executed and how data is filtered across the model.


Not read yet

Use Cases: When to Implement Composite Models

Composite models are not intended to replace standard Import or DirectQuery models in every scenario. Instead, they solve specific architectural challenges that arise in enterprise environments.

  1. Large-Scale Data Integration: You may have a central enterprise data warehouse that handles millions of rows of transaction history (DirectQuery) and a smaller, departmental Excel or SQL table that contains specific budget targets or manual adjustments (Import). A composite model allows you to join these without moving the massive transaction history.
  2. Bridging Siloed Data Sources: Organizations often have data spread across different platforms, such as an Azure SQL Database for operational data and an SAP HANA instance for financial data. Composite models allow you to create relationships between these sources without performing expensive ETL (Extract, Transform, Load) processes to move all data into a single staging area.
  3. Self-Service BI Enhancement: Power BI datasets can be published to the service and used as a source for other reports. With composite models, a user can connect to a published dataset (DirectQuery) and add their own local data (Import) to extend the model without needing to modify the original dataset.

Not read yet

Designing and Building: Step-by-Step

Building a composite model requires careful planning regarding relationships and performance. Follow these steps to implement your first composite model successfully.

Step 1: Establish the Primary Data Source

Start by importing your primary data or connecting to it via DirectQuery. For this example, let’s assume you are connecting to a cloud-based SQL database as your primary DirectQuery source.

  • Go to the Get Data menu.
  • Select your source (e.g., Azure SQL Database).
  • Choose DirectQuery in the connectivity mode dialog.

Step 2: Integrate Additional Sources

Once your first source is loaded, you can add a second source.

  • Select Get Data again.
  • Choose your second source (e.g., a local Excel file or a different SQL server).
  • If you select a source that supports DirectQuery, Power BI will prompt you to confirm if you want to use DirectQuery or Import. If you choose Import, you are now creating a composite model.

Step 3: Define Relationships

This is the most critical step. When you create a relationship between two tables from different source groups, Power BI treats it as a "limited relationship."

  • Navigate to the Model View.
  • Drag and drop the fields to create the relationship.
  • Power BI will automatically set the cross-filter direction and cardinality.
  • Note that for limited relationships, you cannot use certain DAX functions like RELATED or RELATEDTABLE because the data is not physically joined in the same storage engine.

Tip: Managing Limited Relationships Because limited relationships do not allow the engine to "know" the entire scope of the data, you should always ensure that your relationships are based on keys that are as granular as possible. Avoid using relationships on non-unique columns, as this can lead to unpredictable results in your measures.


Not read yet

Performance Considerations and Best Practices

While composite models offer immense flexibility, they introduce complexity that can impact report performance if not managed correctly.

The "Query Folding" Requirement

For your DirectQuery sources, query folding is paramount. Query folding is the ability of Power Query to generate a single query statement to retrieve data from the source. When you build complex transformations in Power Query, ensure they are folded back to the source database. If you apply transformations that cannot be folded, Power BI will be forced to pull all the raw data into memory and process it locally, which defeats the purpose of using DirectQuery.

Minimizing "Chatty" Queries

Every time a user interacts with a report, Power BI generates queries. In a composite model, if a visual uses fields from two different source groups, Power BI must send queries to both sources and join the results. This is often referred to as a "chatter" between the engine and the sources.

  • Keep visuals simple: Avoid putting too many fields from different sources in a single visual.
  • Use Aggregations: Aggregations are the most powerful tool for performance in composite models. You can create a hidden, imported table that contains summarized data (e.g., monthly sales) and link it to the detailed DirectQuery table. Power BI will prioritize the aggregated table for high-level visuals and only hit the detailed DirectQuery table when the user drills down.

Best Practices Table

Feature Best Practice
Data Types Ensure keys used for relationships have identical data types across sources.
Cardinality Use 1:Many relationships; avoid Many:Many where possible to reduce engine overhead.
Aggregations Pre-calculate common metrics in an Import-mode table to avoid hitting the DirectQuery source.
Row-Level Security Apply RLS at the source database level whenever possible to ensure consistency.

Not read yet

Common Pitfalls and How to Avoid Them

1. The "Ambiguous Relationship" Trap

When you have multiple tables from different sources, it is easy to accidentally create multiple active relationships between the same tables. This creates ambiguity, and the Power BI engine will refuse to calculate measures.

  • Fix: Ensure that only one path of active relationships exists between your tables. Use inactive relationships and the USERELATIONSHIP function in DAX if you need to support multiple filtering paths.

2. Ignoring Latency Differences

If you join a lightning-fast SQL server with a slow, legacy on-premises database, your report will only be as fast as the slowest source.

  • Fix: If one source is consistently slow, consider importing a subset of that data into your model instead of using DirectQuery. This balances the performance by keeping the "slow" data cached locally.

3. Over-Reliance on Power Query Transformations

Users often try to perform complex data cleaning in the Power Query editor for DirectQuery sources. If those transformations aren't supported by the source engine, the model will slow down significantly.

  • Fix: Perform complex data cleaning at the database level using Views or Stored Procedures before connecting Power BI. Let the database do the heavy lifting.

Warning: The "Many-to-Many" Performance Hit Many-to-many relationships in a composite model act as a major performance bottleneck. Because the engine must resolve the relationship at query time without the benefit of a clean join index, it can lead to high memory consumption and slow report rendering. Always look for ways to bridge tables using a star-schema design (a dimension table between two fact tables) rather than direct many-to-many relationships.


Not read yet

Advanced DAX with Composite Models

When working with composite models, standard DAX functions behave differently. Because the data originates from different sources, the engine cannot rely on traditional join logic.

Understanding KEEPFILTERS and CROSSFILTER

In a composite model, you might need to force a specific filter behavior because the engine is dealing with potentially disparate schemas. Using KEEPFILTERS in your measures is often safer than relying on the default relationship settings, as it prevents the engine from overriding your intended filter context.

Example: Calculating a Cross-Source Metric

Suppose you have Sales in a DirectQuery SQL table and Budget in an imported Excel file. You want to calculate the variance.

-- This measure operates across two different source groups
Variance = 
VAR ActualSales = SUM('Sales'[Amount])
VAR BudgetSales = SUM('Budget'[Target])
RETURN
ActualSales - BudgetSales

In this example, Power BI sends two separate queries to the respective sources, retrieves the scalar values (the sums), and then performs the subtraction within the local Power BI engine. This is highly efficient because the heavy aggregation happens at the source.


Not read yet

Maintaining Model Integrity

As your model grows, maintaining it becomes a challenge. Documenting the source groups and the purpose of each table is essential.

  1. Use Folder Groups: Organize your tables in the Model view into folders based on their source. This helps you quickly identify which tables are DirectQuery and which are Import.
  2. Naming Conventions: Adopt a strict naming convention for tables and measures. For example, prefixing all measures with the source name can help you track where the data is coming from.
  3. Regular Performance Audits: Use the "Performance Analyzer" in Power BI Desktop to monitor the query duration for each visual. If you notice a visual taking significantly longer than others, check if it is hitting a DirectQuery source unnecessarily.

Scaling Strategy: The "Golden Dataset" Approach

The most effective way to scale composite models is to follow the "Golden Dataset" pattern. In this architecture, you create a core, certified dataset that contains your primary facts and dimensions. You then publish this dataset to the Power BI Service.

Other analysts can then connect to this "Golden Dataset" using DirectQuery and add their own local data (like supplementary Excel files or departmental budgets) to create their own composite models. This allows for a "hub-and-spoke" model where the enterprise data remains consistent and governed, while individual departments retain the flexibility to add their own unique insights.

Managing Permissions

When using a composite model that connects to a published dataset, you must ensure that users have the correct permissions on the source dataset. If a user does not have "Build" permissions on the core dataset, they will be unable to create a composite model on top of it.


Not read yet

Frequently Asked Questions (FAQ)

Q: Can I use RLS (Row-Level Security) in a composite model? A: Yes, but it is complex. You must ensure that the RLS filters are defined for all source groups. If you filter one table, that filter must propagate through the relationships to the other source groups.

Q: Why is my visual showing "Data truncated"? A: This usually happens when you are using DirectQuery and the result set exceeds the row limit enforced by the data source. Check your source database settings or consider using aggregations to summarize the data before it reaches the visual.

Q: Is it possible to convert an Import model to a Composite model? A: Yes. You can change the storage mode of individual tables from Import to DirectQuery by right-clicking the table in the Model view and selecting "Properties" -> "Advanced" -> "Storage mode." However, be aware that this is a one-way street for some tables; once converted to DirectQuery, you may lose some Power Query transformation capabilities.


Not read yet

Summary and Key Takeaways

Composite models are a powerful tool for organizations that need to balance the performance of cached data with the scale of live-connected data warehouses. By understanding how to manage source groups, optimize relationships, and leverage aggregations, you can build models that are both performant and flexible.

Key Takeaways:

  • Hybrid Storage: Composite models allow you to mix Import and DirectQuery modes, providing the best of both worlds—speed and real-time connectivity.
  • Source Groups: Recognize that every time you connect to a new source in DirectQuery, you are creating a new "source group," which has implications for how DAX queries are executed.
  • Aggregations are Essential: To keep your composite models fast, use hidden, imported aggregation tables to handle the bulk of your visual queries, reserving DirectQuery for granular, detailed drill-throughs.
  • Limited Relationships: Be aware that relationships between different source groups are "limited." They do not allow for certain DAX behaviors and require careful design to avoid ambiguity.
  • Performance First: Always prioritize query folding in your DirectQuery sources. If the source database can't handle the transformation, the Power BI engine will struggle, leading to poor user experience.
  • Governance via "Golden Datasets": Utilize a hub-and-spoke model where enterprise-certified datasets serve as the foundation for departmental composite models.
  • Continuous Monitoring: Use the Performance Analyzer regularly to identify bottlenecks in your visual queries, especially when those visuals span multiple source groups.

By mastering these concepts, you move beyond simple report building and into the realm of enterprise-grade data architecture. Composite models require a deeper understanding of how data flows from the source to the screen, but the reward is a highly scalable, flexible, and efficient BI ecosystem that can grow alongside your organization's data needs.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.