Sub topic 11
Composite Models and Dual Tables
Prerequisites
This chapter assumes you have read the Import and DirectQuery chapters. You should know that Import tables are cached in the VertiPaq engine, and that DirectQuery tables send SQL to the source at report time. You should also be comfortable with star schemas and with relationships between fact and dimension tables.
What a composite model is
A composite model is a semantic model whose tables do not all use the same storage mode. Two cases qualify:
- Some tables are Import and others are DirectQuery.
- Several tables use DirectQuery, but they come from more than one source, such as a SQL database and a different database.
Each table has its own storage mode, so you decide per table where the data lives. A common design keeps small dimension tables in memory for fast slicers. The large fact table stays in the source, so you avoid a long refresh and a large memory footprint.
You can also build a composite model on top of another published semantic model, which Power BI calls DirectQuery for Power BI semantic models. Your model then adds its own Import tables, measures, and relationships to the shared one. Support for mixing Direct Lake tables with other modes depends on how the model connects to OneLake, so check the current Microsoft documentation before planning around it.
Setting the storage mode
In Power BI Desktop, open Model view and select a table. In the Properties pane, expand Advanced and choose a value under Storage mode:
| Storage mode | Where data is read from | Typical use in a composite model |
|---|---|---|
| Import | VertiPaq cache | Small dimensions, lookup tables, data from files |
| DirectQuery | The source, at query time | Large fact tables, data that must be fresh |
| Dual | Cache or source, chosen per query | Dimensions related to a DirectQuery fact table |
Changing a table from DirectQuery to Import or Dual is allowed. Changing an Import table back to DirectQuery is not. Plan the direction of the change before you make it.
Why relationships between modes are limited
Power BI groups tables into source groups. All tables from the same DirectQuery source, plus any Dual tables, can be joined in one query that the source runs. Import tables, and DirectQuery tables from other sources, sit in separate islands. A relationship that crosses an island boundary is a limited relationship (also called a weak relationship). In Model view it shows with parentheses at the ends of the line.
Limited relationships behave differently from regular ones:
- Power BI cannot push the join to the source. It runs the query against one island, then passes the result to the other island.
- If an Import dimension filters a DirectQuery fact table, the key values selected in the dimension are sent to the source in the query. With many selected keys, the query gets long and slow.
- Table expansion does not apply, so the blank row for unmatched keys is handled differently. A fact row with no matching dimension row may not appear under a blank category as you expect.
- The DAX function RELATED cannot follow a limited relationship. You need LOOKUPVALUE or a different design.
- Many-to-many cardinality is possible across islands, but it can produce counts that surprise you.
An Import dimension related to a DirectQuery fact table is therefore the pattern that creates the most trouble. Dual tables exist to fix it.
Dual tables
A Dual table is cached in memory like an Import table, and it can also be queried at the source like a DirectQuery table. For each query, the engine picks whichever is cheaper and consistent with the other tables in the query:
- If the query uses only Import and Dual tables, the engine answers it from the cache. A slicer on a Dual dimension is as fast as an Import slicer.
- If the query also uses a DirectQuery table from the same source, the Dual tables act as DirectQuery tables. The relationship is then regular, and the source performs the join.
The Dual table gets the benefit of both modes. The slicer list loads instantly from memory. When the user picks a value, the filter reaches the source inside a single SQL statement.
A Dual table must come from the same source as the DirectQuery tables it relates to. A Dual table from a different source cannot join in the source's SQL, so it behaves as Import for that query and the relationship stays limited.
Worked example
Suppose a SQL database holds a large FactSales table and a small DimProduct table. You set FactSales to DirectQuery and DimProduct to Dual. The relationship runs from DimProduct[ProductKey] to FactSales[ProductKey].
The measure below is the same DAX you would write for any mode. The mode only changes how the engine evaluates it.
Total Sales = SUMX ( FactSales, FactSales[Quantity] * FactSales[UnitPrice] )A visual that shows DimProduct[Category] on rows and [Total Sales] as the value sends a query like this one. You can paste it into DAX Studio, or look at it in Performance Analyzer.
EVALUATE
SUMMARIZECOLUMNS (
DimProduct[Category],
"Total Sales", [Total Sales]
)
ORDER BY DimProduct[Category]Because both tables are in the same source group, the engine translates the query into SQL close to the following. This example is illustrative, and the real statement differs in naming and layout.
SELECT p.Category,
SUM(f.Quantity * f.UnitPrice) AS TotalSales
FROM dbo.FactSales AS f
INNER JOIN dbo.DimProduct AS p
ON f.ProductKey = p.ProductKey
GROUP BY p.Category
ORDER BY p.Category;If DimProduct were Import instead, the source would not receive the join. It would receive a query on FactSales with a filter on the product keys chosen in the visual. That is the limited relationship at work.
A second visual that shows only DimProduct[Category] in a slicer never contacts the source. The Dual table answers it from memory.
Refresh and freshness
A Dual table has a cache, and the cache is refreshed on the semantic model's schedule like an Import table. The DirectQuery fact table is read live. The two can disagree for a short time. If a new product is added to the source, the fact table may contain sales for a key that is missing from the cached DimProduct until the next refresh. In queries that run in the source, the join sees the new product. In queries answered from the cache, it does not. Schedule refresh of Dual tables often enough that this gap is acceptable.
Dual tables also use memory and refresh time, which DirectQuery tables avoid. Keep them to small and medium dimensions, not large tables.
Security and credentials
A composite model has more than one data path, so it has more than one place where credentials and filters apply. Row-level security and source credentials in each mode are covered in a later chapter. For now, remember two points:
- Import and Dual tables are refreshed with the credentials stored on the semantic model, so users see the cached data regardless of their own source permissions unless you add row-level security.
- Data privacy levels matter. When Power BI sends key values from an Import table to a DirectQuery source in a limited relationship, those values leave the model. Make sure that is acceptable for the data involved.
Common mistakes
- Leaving dimensions as Import beside a DirectQuery fact table. The relationship becomes limited, and large key lists are sent to the source. Switch the dimensions to Dual when they come from the same source.
- Setting a dimension to Dual when it comes from a different source than the fact table. It will act as Import for that query, so you get none of the join pushdown.
- Making a very large table Dual. It then costs memory and refresh time like an Import table, and you lose the reason for choosing DirectQuery.
- Assuming RELATED works across every relationship. It fails across limited relationships.
- Forgetting that Dual data is cached. Users may see a dimension that lags behind the live fact table.
Choosing composite design
Use a composite model when one mode alone fails a requirement. Typical reasons:
- The fact table is too large or must be near real time, but the dimensions are small and slicers must be quick.
- Some data comes from a file or spreadsheet that has to be combined with a live database table.
- A central team publishes a shared model, and you need to add local tables and measures.
If all tables can be Import, or all can be Direct Lake, a single-mode model is simpler to reason about, test, and secure. Add the composite complexity only for a specific gain.
Exercise
A model has a DirectQuery FactOrders table and an Import DimCustomer table, both from the same SQL database. Users report slow visuals when they select many customers in a slicer. What storage mode change would you try, and why does it help?
Show answer
Change DimCustomer to Dual. The Import dimension forms a limited relationship with the DirectQuery fact table, so the selected customer keys are sent to the source as a long list of values. As a Dual table from the same source, DimCustomer joins to FactOrders in one regular relationship, and the source runs the join in a single SQL query. Slicers still load from the cache. The cost is that DimCustomer must be refreshed on a schedule so the cache does not lag far behind the source.